using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Markup;
using System.Windows.Media;
using Altova.Types;
using Common;
using Common.Enum;
using Common.NotifyEvent;
using Converters;
using Define;
using device;
using Images;
using MainView.MainControls;
using MainView.MainControls.Chart;
using MainView.StandardCurve;
using MainView.View.Analysis;
using MainView.Windows;
using Microsoft.Win32;
using ProjectView.ProjectControls;
using ProjectView.Windows;
using RDML_v1_2_REC.rdml;
using Report;
using SExperiment;
using SExperiment.ExperimentResult;
using SProject;
using SProject.BasicInformation;
using SProject.Paramter;
using SProject.Program;
using SSettings;
using SWellPlate;

namespace MainView.View
{
	public partial class UCExperiment : UserControl, IComponentConnector
	{
		public delegate void DelegateOnExperimentEvent(object sender, CreateExperimentEventArgs e);

		public delegate void DelegateOnWindowEvent(object sender, EventArgs e);

		private const string File_Docx_Ext = "docx";

		public static readonly RoutedEvent OnExperimentStatusChangedRoutedEvent = EventManager.RegisterRoutedEvent("OnExperimentStatusChangedRoutedEvent", RoutingStrategy.Bubble, typeof(EventHandler<RoutedEventArgs>), typeof(UCExperiment));

		public static readonly DependencyProperty StartTextProperty = DependencyProperty.Register("StartText", typeof(string), typeof(UCExperiment), new PropertyMetadata(null));

		public static readonly DependencyProperty MaxXProperty = DependencyProperty.Register("MaxX", typeof(double?), typeof(UCExperiment), new UIPropertyMetadata(2.0));

		public static readonly DependencyProperty IsEnabledChannel1Property = DependencyProperty.Register("IsEnabledChannel1", typeof(bool), typeof(UCExperiment), new PropertyMetadata(false, OnChannelEnabledChanged));

		public static readonly DependencyProperty IsEnabledChannel2Property = DependencyProperty.Register("IsEnabledChannel2", typeof(bool), typeof(UCExperiment), new PropertyMetadata(false, OnChannelEnabledChanged));

		public static readonly DependencyProperty IsEnabledChannel3Property = DependencyProperty.Register("IsEnabledChannel3", typeof(bool), typeof(UCExperiment), new PropertyMetadata(false, OnChannelEnabledChanged));

		public static readonly DependencyProperty IsEnabledChannel4Property = DependencyProperty.Register("IsEnabledChannel4", typeof(bool), typeof(UCExperiment), new PropertyMetadata(false, OnChannelEnabledChanged));

		public static readonly DependencyProperty IsEnabledChannel5Property = DependencyProperty.Register("IsEnabledChannel5", typeof(bool), typeof(UCExperiment), new PropertyMetadata(false, OnChannelEnabledChanged));

		public static readonly DependencyProperty IsEnabledChannel6Property = DependencyProperty.Register("IsEnabledChannel6", typeof(bool), typeof(UCExperiment), new PropertyMetadata(false, OnChannelEnabledChanged));

		public static readonly DependencyProperty IsSelectedChannel1Property = DependencyProperty.Register("IsSelectedChannel1", typeof(bool), typeof(UCExperiment), new PropertyMetadata(false, OnChannelSelectedChanged));

		public static readonly DependencyProperty IsSelectedChannel2Property = DependencyProperty.Register("IsSelectedChannel2", typeof(bool), typeof(UCExperiment), new PropertyMetadata(false, OnChannelSelectedChanged));

		public static readonly DependencyProperty IsSelectedChannel3Property = DependencyProperty.Register("IsSelectedChannel3", typeof(bool), typeof(UCExperiment), new PropertyMetadata(false, OnChannelSelectedChanged));

		public static readonly DependencyProperty IsSelectedChannel4Property = DependencyProperty.Register("IsSelectedChannel4", typeof(bool), typeof(UCExperiment), new PropertyMetadata(false, OnChannelSelectedChanged));

		public static readonly DependencyProperty IsSelectedChannel5Property = DependencyProperty.Register("IsSelectedChannel5", typeof(bool), typeof(UCExperiment), new PropertyMetadata(false, OnChannelSelectedChanged));

		public static readonly DependencyProperty IsSelectedChannel6Property = DependencyProperty.Register("IsSelectedChannel6", typeof(bool), typeof(UCExperiment), new PropertyMetadata(false, OnChannelSelectedChanged));

		private string password;

		public static readonly DependencyProperty IsDecryptProperty = DependencyProperty.Register("IsDecrypt", typeof(bool), typeof(UCExperiment), new UIPropertyMetadata(true));

		private Experiment _Experiment;

		private bool _IsModified;

		private bool isFirstUCExperiment_Loaded = true;

		private bool shouldSetButton;

		private bool _IsCheckChannel = true;

		private string rdml_file_inside_data_name = "rdml_data.xml";

		public string RdmlExt = "rdml";

		private bool? _IsGridBasicSettingInit = null;

		private UCWellEdit _UCWellEdit;

		private bool? _IsGridWellEditInit = null;

		private List<int> channelList = new List<int>();

		private bool? _IsGridSampleInfoInit = null;

		private UCSampleInfo _UCSampleInfo;

		private bool _refreshWell;

		private bool? _IsGridExperimentRunInit = null;

		private UCExperimentRun _UCExperimentRun;

		private bool? _IsGridExperimentRunCompleteInit = null;

		private bool _RefreshProjectInfo = true;

		private UCExperimentRunComplete _UCExperimentRunComplete;

		private bool? _IsGridExperimentAnalysisInit = null;

		private BaseAnalysis _UCExperimentAnalysis;

		public string StartText
		{
			get
			{
				return (string)GetValue(StartTextProperty);
			}
			set
			{
				SetValue(StartTextProperty, value);
			}
		}

		public double? MaxX
		{
			get
			{
				return (double?)GetValue(MaxXProperty);
			}
			set
			{
				SetValue(MaxXProperty, value);
			}
		}

		public bool IsEnabledChannel1
		{
			get
			{
				return (bool)GetValue(IsEnabledChannel1Property);
			}
			set
			{
				SetValue(IsEnabledChannel1Property, value);
			}
		}

		public bool IsEnabledChannel2
		{
			get
			{
				return (bool)GetValue(IsEnabledChannel2Property);
			}
			set
			{
				SetValue(IsEnabledChannel2Property, value);
			}
		}

		public bool IsEnabledChannel3
		{
			get
			{
				return (bool)GetValue(IsEnabledChannel3Property);
			}
			set
			{
				SetValue(IsEnabledChannel3Property, value);
			}
		}

		public bool IsEnabledChannel4
		{
			get
			{
				return (bool)GetValue(IsEnabledChannel4Property);
			}
			set
			{
				SetValue(IsEnabledChannel4Property, value);
			}
		}

		public bool IsEnabledChannel5
		{
			get
			{
				return (bool)GetValue(IsEnabledChannel5Property);
			}
			set
			{
				SetValue(IsEnabledChannel5Property, value);
			}
		}

		public bool IsEnabledChannel6
		{
			get
			{
				return (bool)GetValue(IsEnabledChannel6Property);
			}
			set
			{
				SetValue(IsEnabledChannel6Property, value);
			}
		}

		public bool IsSelectedChannel1
		{
			get
			{
				return (bool)GetValue(IsSelectedChannel1Property);
			}
			set
			{
				SetValue(IsSelectedChannel1Property, value);
			}
		}

		public bool IsSelectedChannel2
		{
			get
			{
				return (bool)GetValue(IsSelectedChannel2Property);
			}
			set
			{
				SetValue(IsSelectedChannel2Property, value);
			}
		}

		public bool IsSelectedChannel3
		{
			get
			{
				return (bool)GetValue(IsSelectedChannel3Property);
			}
			set
			{
				SetValue(IsSelectedChannel3Property, value);
			}
		}

		public bool IsSelectedChannel4
		{
			get
			{
				return (bool)GetValue(IsSelectedChannel4Property);
			}
			set
			{
				SetValue(IsSelectedChannel4Property, value);
			}
		}

		public bool IsSelectedChannel5
		{
			get
			{
				return (bool)GetValue(IsSelectedChannel5Property);
			}
			set
			{
				SetValue(IsSelectedChannel5Property, value);
			}
		}

		public bool IsSelectedChannel6
		{
			get
			{
				return (bool)GetValue(IsSelectedChannel6Property);
			}
			set
			{
				SetValue(IsSelectedChannel6Property, value);
			}
		}

		public bool IsDecrypt
		{
			get
			{
				return (bool)GetValue(IsDecryptProperty);
			}
			set
			{
				SetValue(IsDecryptProperty, value);
			}
		}

		public Experiment Experiment
		{
			get
			{
				return _Experiment;
			}
			set
			{
				_Experiment = value;
			}
		}

		public event DelegateOnExperimentEvent OnExperimentNew;

		public event DelegateOnWindowEvent OnWindowClose;

		public event RoutedEventHandler OnExperimentStatusChanged
		{
			add
			{
				AddHandler(OnExperimentStatusChangedRoutedEvent, value);
			}
			remove
			{
				RemoveHandler(OnExperimentStatusChangedRoutedEvent, value);
			}
		}

		private void RaiseExperimentStatusChanged()
		{
			RaiseEvent(new RoutedEventArgs
			{
				RoutedEvent = OnExperimentStatusChangedRoutedEvent
			});
		}

		private static void OnChannelEnabledChanged(object sender, DependencyPropertyChangedEventArgs args)
		{
			UCExperiment uCExperiment = sender as UCExperiment;
			int result = 0;
			int.TryParse(args.Property.Name.Last().ToString(), out result);
			if (!(bool)args.NewValue)
			{
				uCExperiment.DisplayChannel(result, false);
			}
		}

		private static void OnChannelSelectedChanged(object sender, DependencyPropertyChangedEventArgs args)
		{
			UCExperiment uCExperiment = sender as UCExperiment;
			int result = 0;
			int.TryParse(args.Property.Name.Last().ToString(), out result);
			if (result != 0)
			{
				uCExperiment.DisplayChannel(result, (bool)args.NewValue);
			}
		}

		[DllImport("user32.dll")]
		public static extern int MessageBeep(uint n);

		public UCExperiment(Experiment experiment)
		{
			_Experiment = experiment;
			base.DataContext = _Experiment;
			RefreshStartText();
			InitializeComponent();
			tbChannel1.SetBinding(ToggleButton.IsCheckedProperty, new Binding("IsSelectedChannel1")
			{
				Source = this
			});
			tbChannel1.SetBinding(UIElement.IsEnabledProperty, new Binding("IsEnabledChannel1")
			{
				Source = this
			});
			tbChannel2.SetBinding(ToggleButton.IsCheckedProperty, new Binding("IsSelectedChannel2")
			{
				Source = this
			});
			tbChannel2.SetBinding(UIElement.IsEnabledProperty, new Binding("IsEnabledChannel2")
			{
				Source = this
			});
			tbChannel3.SetBinding(ToggleButton.IsCheckedProperty, new Binding("IsSelectedChannel3")
			{
				Source = this
			});
			tbChannel3.SetBinding(UIElement.IsEnabledProperty, new Binding("IsEnabledChannel3")
			{
				Source = this
			});
			tbChannel4.SetBinding(ToggleButton.IsCheckedProperty, new Binding("IsSelectedChannel4")
			{
				Source = this
			});
			tbChannel4.SetBinding(UIElement.IsEnabledProperty, new Binding("IsEnabledChannel4")
			{
				Source = this
			});
			tbChannel5.SetBinding(ToggleButton.IsCheckedProperty, new Binding("IsSelectedChannel5")
			{
				Source = this
			});
			tbChannel5.SetBinding(UIElement.IsEnabledProperty, new Binding("IsEnabledChannel5")
			{
				Source = this
			});
			tbChannel6.SetBinding(ToggleButton.IsCheckedProperty, new Binding("IsSelectedChannel6")
			{
				Source = this
			});
			tbChannel6.SetBinding(UIElement.IsEnabledProperty, new Binding("IsEnabledChannel6")
			{
				Source = this
			});
			ExperimentChanged();
			AddHandler(UCWellInfo.OnChannelNoChangedRoutedEvent, new RoutedEventHandler(OnChannelNoChanged_RoutedEvent), true);
			AddHandler(UCHRMOption.OnOptionChangedRoutedEvent, new RoutedEventHandler(OnOptionChanged_RoutedEvent), true);
			AddHandler(UCPlate.OnItemUpdateRoutedEvent, new RoutedEventHandler(OnItemUpdate_RoutedEvent), true);
			AddHandler(BaseCurveChart.OnItemUpdateRoutedEvent, new RoutedEventHandler(OnItemUpdate_RoutedEvent), true);
			RegisterEvent();
			ViewControlByIni();
			base.Loaded += After_Load;
		}

		private void RefreshStartText()
		{
			switch (Experiment.Status)
			{
			case EExperimentStatus.NotRunning:
				if (Experiment.Program != null && Experiment.Program.IsContainsPreHeatSegment())
				{
					StartText = Utility.GetMessage("preheat");
				}
				else
				{
					StartText = Utility.GetMessage("start");
				}
				break;
			case EExperimentStatus.Interrupt:
				if (Experiment.Program != null && Experiment.Program.IsContainsPreHeatSegment() && !Experiment.Device.PreHeatIsStop)
				{
					StartText = Utility.GetMessage("preheat");
				}
				else
				{
					StartText = Utility.GetMessage("start");
				}
				break;
			case EExperimentStatus.AbnormalInterrupt:
				StartText = Utility.GetMessage("continue");
				break;
			case EExperimentStatus.Running:
				if (Experiment.Program != null && Experiment.Program.IsContainsPreHeatSegment())
				{
					if (Experiment.Device.PreHeatIsStop)
					{
						StartText = Utility.GetMessage("interrupt");
					}
					else
					{
						StartText = Utility.GetMessage("start");
					}
				}
				else
				{
					StartText = Utility.GetMessage("interrupt");
				}
				break;
			case EExperimentStatus.Completed:
				StartText = Utility.GetMessage("completed");
				break;
			}
		}

		private void After_Load(object sender, EventArgs e)
		{
			if (isFirstUCExperiment_Loaded)
			{
				if (Experiment.Status == EExperimentStatus.AbnormalInterrupt)
				{
					Experiment.Status = EExperimentStatus.NotRunning;
					TabControlExperiment.SelectedItem = TabItemExperimentRun;
					if (Experiment.Device.RunState != 0)
					{
						Experiment.Continue();
					}
				}
				else if (Experiment.Status == EExperimentStatus.Completed)
				{
					TabControlExperiment.SelectedItem = TabItemExperimentAnalysis;
				}
				isFirstUCExperiment_Loaded = false;
			}
			if (base.ActualWidth > 100.0 && base.ActualWidth < 1450.0)
			{
				shouldSetButton = true;
				Buttoncontrol();
			}
		}

		private void Buttoncontrol()
		{
			if (!shouldSetButton)
			{
				return;
			}
			bool flag = _Experiment.ExperimentSetting.UseSubset;
			if (base.ActualWidth > 100.0 && base.ActualWidth <= 1280.0)
			{
				flag = true;
			}
			SaveAs_Button.Visibility = (flag ? Visibility.Collapsed : Visibility.Visible);
			menuFile.ShowCaption = ((!flag) ? Visibility.Collapsed : Visibility.Visible);
			experiment_table.Visibility = (flag ? Visibility.Collapsed : Visibility.Visible);
			experiment_encryption_button.Visibility = (flag ? Visibility.Collapsed : Visibility.Visible);
			experiment_template_button.Visibility = (flag ? Visibility.Collapsed : Visibility.Visible);
			foreach (object menuItem3 in menuPrint.MenuItems)
			{
				MenuItem menuItem = menuItem3 as MenuItem;
				if (menuItem != null && menuItem.Header.Equals(Utility.GetMessage("experiment_table")))
				{
					menuItem.Visibility = ((!flag) ? Visibility.Collapsed : Visibility.Visible);
				}
			}
			foreach (object item in menuExport.Items)
			{
				MenuItem menuItem2 = item as MenuItem;
				if (menuItem2 != null && menuItem2.Header.Equals(Utility.GetMessage("epr_experiment_quick")))
				{
					menuItem2.Visibility = ((!flag) ? Visibility.Collapsed : Visibility.Visible);
				}
			}
		}

		private void ViewControlByIni()
		{
			foreach (object item in menuExport.Items)
			{
				MenuItem menuItem = item as MenuItem;
				if (menuItem != null && menuItem.Header.Equals(Utility.GetMessage("upLoad_ExperimentData")))
				{
					menuItem.Visibility = (string.IsNullOrEmpty(ConfigReader.GetInstance().GetUpLoad_UrlFromIni()) ? Visibility.Collapsed : Visibility.Visible);
				}
				if (menuItem != null && menuItem.Header.Equals(Utility.GetMessage("export_experimentData_ByIndex")))
				{
					menuItem.Visibility = (string.IsNullOrEmpty(ConfigReader.GetInstance().GetUpLoad_UrlFromIni()) ? Visibility.Collapsed : Visibility.Visible);
				}
			}
		}

		private void RegisterEvent()
		{
			RegisterExperimentEvent();
		}

		private void RegisterExperimentEvent()
		{
			Experiment.Event += Experiment_Event;
			Experiment.ExperimentSetting.Event += ExperimentSetting_Event;
			Experiment.Device.RawDataChangedEvent += Device_RawDataChangedEvent;
			Experiment.Device.OperationEnableEvent += Device_OperationEnableEvent;
			Experiment.Device.RunErrorEvent += Device_RunErrorEvent;
			Experiment.Device.CheckOrderEvent += Device_CheckOrderEvent;
		}

		private void Device_CheckOrderEvent(object sender, EventArgs e)
		{
			string text = DumpInvoke.CheckOrder(Experiment);
			if (string.IsNullOrEmpty(text))
			{
				Experiment.Device.ProgramRunAfterCheckOrder();
				return;
			}
			Experiment.Stop();
			MessageBox.Show(text);
		}

		private void ExperimentSetting_Event(object sender, EventArgs e)
		{
			_IsModified = true;
		}

		private void OnChannelNoChanged_RoutedEvent(object sender, RoutedEventArgs e)
		{
			ChannelNoChangedRoutedEventArgs channelNoChangedRoutedEventArgs = e as ChannelNoChangedRoutedEventArgs;
			if (channelNoChangedRoutedEventArgs != null)
			{
				_IsCheckChannel = false;
				for (int i = 1; i < channelNoChangedRoutedEventArgs.ChannelDisplay.Count() + 1; i++)
				{
					SetChannelStatus(i, GetChannelEnableStatus(i) && channelNoChangedRoutedEventArgs.ChannelDisplay[i - 1]);
				}
				_IsCheckChannel = true;
			}
		}

		private void OnOptionChanged_RoutedEvent(object sender, RoutedEventArgs e)
		{
			_IsModified = true;
		}

		private void OnItemUpdate_RoutedEvent(object sender, RoutedEventArgs e)
		{
			_IsModified = true;
			base.Dispatcher.BeginInvoke((Action)delegate
			{
				CommandManager.InvalidateRequerySuggested();
			});
		}

		private bool CanClose()
		{
			if (Experiment.Status != EExperimentStatus.Running)
			{
				return Experiment.Device.OperationEnable;
			}
			return false;
		}

		public bool Close()
		{
			if (!CanClose())
			{
				return false;
			}
			if (_IsModified && _Experiment.CanSave() && IsDecrypt)
			{
				switch (MessageBox.Show(Utility.GetMainWindow(), string.Format(Utility.GetMessage("msg_save_experiment_confirm"), _Experiment.Name), Utility.GetMessage("Warning"), MessageBoxButton.YesNoCancel, MessageBoxImage.Question, MessageBoxResult.Yes))
				{
				case MessageBoxResult.Cancel:
					return false;
				case MessageBoxResult.Yes:
					CommandBinding_Save_Executed(this, null);
					break;
				}
			}
			if (this.OnWindowClose != null)
			{
				this.OnWindowClose(this, new EventArgs());
			}
			if (_UCWellEdit != null)
			{
				_UCWellEdit.Dispose();
			}
			if (_UCExperimentRun != null)
			{
				_UCExperimentRun.Dispose();
			}
			if (_UCExperimentRunComplete != null)
			{
				_UCExperimentRunComplete.Dispose();
			}
			if (_UCExperimentAnalysis != null)
			{
				_UCExperimentAnalysis.Dispose();
			}
			return true;
		}

		public void SelectExperimentRun()
		{
			TabControlExperiment.SelectedItem = TabItemExperimentRun;
		}

		private void ExperimentAnalysis(bool realtime = true, bool refreshData = true)
		{
			if (!Experiment.HasData())
			{
				return;
			}
			AnalyseError error = null;
			try
			{
				error = DumpInvoke.DataAnalyse(Experiment, realtime);
			}
			catch (Exception ex)
			{
				if (!realtime)
				{
					base.Dispatcher.BeginInvoke((Action)delegate
					{
						MessageBox.Show(Utility.GetMainWindow(), Utility.GetMessage("msg_AnalysisError"));
					});
				}
				Log.WriteLine(string.Format("Analysis Error:{0}", ex.Message));
				return;
			}
			if (error != null)
			{
				base.Dispatcher.BeginInvoke((Action)delegate
				{
					if (error.StdDotIsNotEnoughTargetList.Count > 0)
					{
						List<string> prjNameList = new List<string>();
						StandardWellNotEnoughWindow standardWellNotEnoughWindow = new StandardWellNotEnoughWindow
						{
							Owner = Utility.GetMainWindow()
						};
						List<TemplateData> list = new List<TemplateData>();
						for (int i = 0; i < error.StdDotIsNotEnoughTargetList.Count; i += 2)
						{
							list.Add(new TemplateData
							{
								prjName = error.StdDotIsNotEnoughTargetList[i],
								prjTarget = error.StdDotIsNotEnoughTargetList[i + 1]
							});
						}
						standardWellNotEnoughWindow.TemplateDatas = list;
						standardWellNotEnoughWindow.ShowDialog();
						if (standardWellNotEnoughWindow.DialogResult == true)
						{
							CallLoadSubsetStandardCurveWindow(prjNameList);
						}
					}
					if (error.RawDataIsTooFew)
					{
						MessageBox.Show(Utility.GetMainWindow(), Utility.GetMessage("msg_RawDataIsTooFew"));
					}
					if (error.MeltingRawDataIsTooFew)
					{
						MessageBox.Show(Utility.GetMainWindow(), Utility.GetMessage("msg_MeltingRawDataIsTooFew"));
					}
					if (!string.IsNullOrEmpty(error.JudgeErrorMessage))
					{
						MessageBox.Show(Utility.GetMainWindow(), error.JudgeErrorMessage);
					}
					if (error.MoreThanTwoStdInCluster)
					{
						MessageBox.Show(Utility.GetMainWindow(), Utility.GetMessage("msg_MoreThanTwoStdInCluster"));
					}
					if (error.NoStd)
					{
						MessageBox.Show(Utility.GetMainWindow(), Utility.GetMessage("msg_NoStd"));
					}
					if (error.StdIsTooMany)
					{
						MessageBox.Show(Utility.GetMainWindow(), Utility.GetMessage("msg_StdIsTooMany"));
					}
				});
			}
			if (!realtime)
			{
				if (_UCExperimentAnalysis != null)
				{
					_UCExperimentAnalysis.RefreshAllData();
				}
			}
			else if (_UCExperimentRun != null)
			{
				_UCExperimentRun.RefreshWellInfoData();
				_UCExperimentRun.RefreshChartInfo(refreshData);
			}
		}

		private void ExperimentChanged()
		{
			IsDecrypt = string.IsNullOrEmpty(Experiment.Password);
			ProgramChanged(Experiment.Program);
		}

		private void ProgramChanged(PCRProgram program)
		{
			int num = 0;
			if (program != null)
			{
				num = program.GetAcquisitionCycleCount();
			}
			MaxX = num;
		}

		private void DisplayChannel(int channelNo, bool visible)
		{
			if (!_IsCheckChannel)
			{
				return;
			}
			if (!IsSelectedChannel1 && !IsSelectedChannel2 && !IsSelectedChannel3 && !IsSelectedChannel4 && !IsSelectedChannel5 && !IsSelectedChannel6 && GetChannelEnableStatus(channelNo))
			{
				SetChannelStatus(channelNo, true);
				return;
			}
			if (_Experiment.ExperimentSetting.ChannelSelectMode == EChannelSelectMode.MultiClickCtl && (Keyboard.Modifiers & ModifierKeys.Control) != ModifierKeys.Control)
			{
				_IsCheckChannel = false;
				for (int i = 1; i <= 6; i++)
				{
					if (i != channelNo)
					{
						SetChannelStatus(i, false);
					}
				}
				if (!visible)
				{
					SetChannelStatus(channelNo, true);
				}
				_IsCheckChannel = true;
			}
			DisplayAllChannel();
		}

		private void DisplayAllChannel()
		{
			bool[] channelDisplay = new bool[6] { IsSelectedChannel1, IsSelectedChannel2, IsSelectedChannel3, IsSelectedChannel4, IsSelectedChannel5, IsSelectedChannel6 };
			bool all = IsSelectedChannel1 == IsEnabledChannel1 && IsSelectedChannel2 == IsEnabledChannel2 && IsSelectedChannel3 == IsEnabledChannel3 && IsSelectedChannel4 == IsEnabledChannel4 && IsSelectedChannel5 == IsEnabledChannel5 && IsSelectedChannel6 == IsEnabledChannel6;
			if (_UCExperimentRun != null && Experiment.Status != EExperimentStatus.Completed)
			{
				_UCExperimentRun.DisplayChannel(channelDisplay, all);
			}
			if (_UCExperimentAnalysis != null && Experiment.Status == EExperimentStatus.Completed)
			{
				_UCExperimentAnalysis.DisplayChannel(channelDisplay, all);
			}
		}

		private void SetChannelStatus(int channelNo, bool status)
		{
			switch (channelNo)
			{
			case 1:
				IsSelectedChannel1 = status;
				break;
			case 2:
				IsSelectedChannel2 = status;
				break;
			case 3:
				IsSelectedChannel3 = status;
				break;
			case 4:
				IsSelectedChannel4 = status;
				break;
			case 5:
				IsSelectedChannel5 = status;
				break;
			case 6:
				IsSelectedChannel6 = status;
				break;
			}
		}

		private bool GetChannelEnableStatus(int channelNo)
		{
			switch (channelNo)
			{
			case 1:
				return IsEnabledChannel1;
			case 2:
				return IsEnabledChannel2;
			case 3:
				return IsEnabledChannel3;
			case 4:
				return IsEnabledChannel4;
			case 5:
				return IsEnabledChannel5;
			case 6:
				return IsEnabledChannel6;
			default:
				return false;
			}
		}

		private void SetChannelEnableStatus(int channelNo, bool status)
		{
			switch (channelNo)
			{
			case 1:
				IsEnabledChannel1 = status;
				break;
			case 2:
				IsEnabledChannel2 = status;
				break;
			case 3:
				IsEnabledChannel3 = status;
				break;
			case 4:
				IsEnabledChannel4 = status;
				break;
			case 5:
				IsEnabledChannel5 = status;
				break;
			case 6:
				IsEnabledChannel6 = status;
				break;
			}
			SetChannelStatus(channelNo, status);
		}

		private void MenuItemExperimentGuid_Click(object sender, RoutedEventArgs e)
		{
			if (this.OnExperimentNew != null)
			{
				this.OnExperimentNew(sender, new CreateExperimentEventArgs
				{
					CreateMode = EExperimentCreateMode.Guid
				});
			}
		}

		private void MenuItemExperimentQuick_Click(object sender, RoutedEventArgs e)
		{
			if (this.OnExperimentNew != null)
			{
				this.OnExperimentNew(sender, new CreateExperimentEventArgs
				{
					CreateMode = EExperimentCreateMode.Quick
				});
			}
		}

		private void MenuItemExperimentTemplateRun_Click(object sender, RoutedEventArgs e)
		{
			if (this.OnExperimentNew != null)
			{
				this.OnExperimentNew(sender, new CreateExperimentEventArgs
				{
					CreateMode = EExperimentCreateMode.Template
				});
			}
		}

		private void MenuItemExperimentRunLast_Click(object sender, RoutedEventArgs e)
		{
			if (this.OnExperimentNew != null)
			{
				this.OnExperimentNew(sender, new CreateExperimentEventArgs
				{
					CreateMode = EExperimentCreateMode.Last
				});
			}
		}

		private void CommandBinding_Open_CanExecute(object sender, CanExecuteRoutedEventArgs e)
		{
			e.CanExecute = this.OnExperimentNew != null;
		}

		private void CommandBinding_Open_Executed(object sender, ExecutedRoutedEventArgs e)
		{
			if (this.OnExperimentNew != null)
			{
				this.OnExperimentNew(sender, new CreateExperimentEventArgs
				{
					CreateMode = EExperimentCreateMode.OpenFile
				});
			}
		}

		private void CommandBinding_Close_CanExecute(object sender, CanExecuteRoutedEventArgs e)
		{
			e.CanExecute = CanClose();
		}

		private void CommandBinding_Close_Executed(object sender, ExecutedRoutedEventArgs e)
		{
			Close();
		}

		private void CommandBinding_Save_CanExecute(object sender, CanExecuteRoutedEventArgs e)
		{
			e.CanExecute = Experiment != null && Experiment.CanSave() && _IsModified && IsDecrypt;
		}

		private void CommandBinding_Save_Executed(object sender, ExecutedRoutedEventArgs e)
		{
			SaveExperiment();
		}

		private void CommandBinding_SaveAs_CanExecute(object sender, CanExecuteRoutedEventArgs e)
		{
			e.CanExecute = Experiment != null && Experiment.CanSave();
		}

		private void CommandBinding_SaveAs_Executed(object sender, ExecutedRoutedEventArgs e)
		{
			SaveExperiment(true);
		}

		private void SaveExperiment(bool saveAs = false)
		{
			if (!Experiment.CanSave())
			{
				return;
			}
			if (saveAs)
			{
				SaveFileDialog saveFileDialog = new SaveFileDialog();
				saveFileDialog.Title = Utility.GetMessage("SaveAs");
				saveFileDialog.Filter = string.Format("{0}{1}|*.{2}", Experiment.FileExt, Utility.GetMessage("File"), Experiment.FileExt);
				saveFileDialog.FileName = Experiment.Name;
				saveFileDialog.FilterIndex = 1;
				saveFileDialog.RestoreDirectory = true;
				saveFileDialog.DefaultExt = Experiment.FileExt;
				if (saveFileDialog.ShowDialog() == true)
				{
					Experiment.Save(saveFileDialog.FileName);
					saveHistory();
					_IsModified = false;
				}
			}
			else
			{
				if (!Utility.ValidateFileName(Experiment.Name))
				{
					MessageBox.Show(Utility.GetMainWindow(), string.Format(Utility.GetMessage("msg_filename_illegalcharacter"), Utility.GetFileNameIllegalCharacter().ToString()));
					TabControlExperiment.SelectedIndex = 0;
					return;
				}
				Experiment.Save(Experiment.FilePath);
				_IsModified = false;
				saveHistory();
			}
			if (ConfigSettings.GetInstance().BasicSetting.AutoSaveOption != EAutoSaveType.AutoSave || _UCExperimentAnalysis == null || !_UCExperimentAnalysis.isLoad)
			{
				return;
			}
			if (ConfigSettings.GetInstance().ExperimentSetting.CustomExport)
			{
				if (File.Exists(ExperimentSetting.InternalCustomExportName))
				{
					string text = _UCExperimentAnalysis.ExportDefaultExperimentData();
					string text2 = ((_Experiment.CurrentSubset.GetQuantitativeProjectList().Count == 0) ? "0" : "1");
					Process.Start(ExperimentSetting.InternalCustomExportName, "\"" + text + "\" " + text2 + " " + 1);
				}
			}
			else
			{
				_UCExperimentAnalysis.AutoExportExperimentData();
			}
		}

		private void saveHistory()
		{
			if (!string.IsNullOrEmpty(Experiment.Auditor))
			{
				ConfigSettings.GetInstance().History.AddExperimentAuditor(Experiment.Auditor);
			}
			if (!string.IsNullOrEmpty(Experiment.Operator))
			{
				ConfigSettings.GetInstance().History.AddExperimentOperator(Experiment.Operator);
			}
		}

		private void CommandBinding_Encrpty_CanExecute(object sender, CanExecuteRoutedEventArgs e)
		{
			e.CanExecute = true;
		}

		private void CommandBinding_Encrpty_Executed(object sender, ExecutedRoutedEventArgs e)
		{
			if (!string.IsNullOrEmpty(Experiment.Password) && Experiment.Password != password)
			{
				PasswordValidateWindow passwordValidateWindow = new PasswordValidateWindow();
				passwordValidateWindow.Password = Experiment.Password;
				passwordValidateWindow.Owner = Utility.GetMainWindow();
				if (passwordValidateWindow.ShowDialog() == true)
				{
					password = passwordValidateWindow.InputPassword;
					IsDecrypt = true;
				}
				return;
			}
			ExperimentEncryptWindow experimentEncryptWindow = new ExperimentEncryptWindow();
			experimentEncryptWindow.Owner = Utility.GetMainWindow();
			if (experimentEncryptWindow.ShowDialog() == true)
			{
				Experiment.Password = experimentEncryptWindow.InputPassword;
				password = experimentEncryptWindow.InputPassword;
				_IsModified = true;
				IsDecrypt = true;
			}
		}

		private void CommandBinding_Print_PatientReport_CanExecute(object sender, CanExecuteRoutedEventArgs e)
		{
			if (TabControlExperiment.SelectedItem == TabItemExperimentAnalysis && _UCExperimentAnalysis != null)
			{
				e.CanExecute = _UCExperimentAnalysis.CanExportPatientReport();
			}
		}

		private void CommandBinding_Print_PatientReport_Executed(object sender, ExecutedRoutedEventArgs e)
		{
			if (_UCExperimentAnalysis == null)
			{
				return;
			}
			Utility.GetMainWindow().Cursor = Cursors.Wait;
			try
			{
				List<Well> list = _UCExperimentAnalysis.GetSelectedUnknownWell();
				switch (Experiment.ExperimentSetting.SampleSortMode)
				{
				case ESampleSortMode.Column:
					list = (from s in list
						orderby s.ColumnIndex, s.RowIndex
						select s).ToList();
					break;
				case ESampleSortMode.Row:
					list = (from s in list
						orderby s.RowIndex, s.ColumnIndex
						select s).ToList();
					break;
				case ESampleSortMode.Module:
					list = (from s in list
						orderby s.ModelA, s.RowIndex, s.ColumnIndex
						select s).ToList();
					break;
				}
				ProjectReportSetting projectReportSetting = ConfigSettings.GetInstance().ProjectReportSetting;
				List<string> list2 = new List<string>();
				foreach (Well item in list)
				{
					string name = item.Project.BasicInfo.Name;
					string projectReport = projectReportSetting.GetProjectReport(name);
					if (!File.Exists(Utility.GetReportTemplatePath() + projectReport) && !list2.Contains(name))
					{
						list2.Add(name);
					}
				}
				if (list2.Count > 0)
				{
					StringBuilder stringBuilder = new StringBuilder();
					stringBuilder.Append(Utility.GetMessage("msg_notset_project_report"));
					stringBuilder.AppendLine();
					foreach (string item2 in list2)
					{
						stringBuilder.AppendLine(item2);
					}
					if (MessageBox.Show(Utility.GetMainWindow(), stringBuilder.ToString(), Utility.GetMessage("Warning"), MessageBoxButton.YesNo, MessageBoxImage.Exclamation, MessageBoxResult.Yes) == MessageBoxResult.Yes)
					{
						MenuItemProjectReport_Click(null, null);
					}
				}
				ExperimentPetientReportWindow experimentPetientReportWindow = new ExperimentPetientReportWindow(_Experiment, _UCExperimentAnalysis.GetAMPChart(), list);
				experimentPetientReportWindow.Owner = Utility.GetMainWindow();
				Utility.GetMainWindow().Cursor = Cursors.Arrow;
				experimentPetientReportWindow.ShowDialog();
			}
			catch (Exception ex)
			{
				Log.WriteLine(ex.StackTrace);
			}
			finally
			{
				Utility.GetMainWindow().Cursor = Cursors.Arrow;
			}
		}

		private void CommandBinding_Print_ExperimentTable_CanExecute(object sender, CanExecuteRoutedEventArgs e)
		{
			e.CanExecute = TabControlExperiment.SelectedItem == TabItemExperimentAnalysis;
		}

		private void CommandBinding_Print_ExperimentTable_Executed(object sender, ExecutedRoutedEventArgs e)
		{
			if (_UCExperimentAnalysis != null)
			{
				int printMode = ConfigReader.GetInstance().GetPrintMode();
				switch (printMode)
				{
				case 0:
					base.Cursor = Cursors.Wait;
					_UCExperimentAnalysis.ucWellInfo.PrintWellInfo();
					base.Cursor = Cursors.Arrow;
					break;
				case 1:
				{
					ReportWindowForLizhu reportWindowForLizhu = new ReportWindowForLizhu(_Experiment);
					reportWindowForLizhu.Owner = Utility.GetMainWindow();
					reportWindowForLizhu.ShowDialog();
					break;
				}
				case 2:
				{
					ReportWindowCustom reportWindowCustom = new ReportWindowCustom(_Experiment, printMode, _UCExperimentAnalysis.GetAMPChart(), _UCExperimentAnalysis.ucWellInfo.GetCurrentTargets());
					reportWindowCustom.Owner = Utility.GetMainWindow();
					reportWindowCustom.ShowDialog();
					break;
				}
				}
			}
		}

		private void CommandBinding_Create_Experiment_Report_Executed(object sender, ExecutedRoutedEventArgs e)
		{
			CreateExperimentReportWindow createExperimentReportWindow = new CreateExperimentReportWindow();
			createExperimentReportWindow.Owner = Utility.GetMainWindow();
			if (createExperimentReportWindow.ShowDialog() == true)
			{
				string text = Utility.GetReportTemplatePath() + createExperimentReportWindow.file_name.Text + ".docx";
				if (!File.Exists(text) || MessageBox.Show(Utility.GetMainWindow(), string.Format(Utility.GetMessage("msg_file_exist_cover")), Utility.GetMessage("warning"), MessageBoxButton.YesNo) != MessageBoxResult.No)
				{
					WordOperator.CreateDocxFile(text);
					Process.Start(text);
				}
			}
		}

		private void CommandBinding_Edit_Experiment_Report_Executed(object sender, ExecutedRoutedEventArgs e)
		{
			OpenFileDialog openFileDialog = new OpenFileDialog();
			openFileDialog.Title = Utility.GetMessage("edit_experiment_report");
			openFileDialog.Filter = string.Format("{0}{1}|*.{0}", "docx", Utility.GetMessage("File"));
			openFileDialog.InitialDirectory = Utility.GetReportTemplatePath();
			if (openFileDialog.ShowDialog() == true)
			{
				Process.Start(openFileDialog.FileName);
			}
		}

		private void MenuItemProjectReport_Click(object sender, RoutedEventArgs e)
		{
			ProjectReportWindow projectReportWindow = new ProjectReportWindow();
			projectReportWindow.Owner = Utility.GetMainWindow();
			projectReportWindow.ShowDialog();
		}

		private void CommandBinding_Export_ExperimentData_CanExecute(object sender, CanExecuteRoutedEventArgs e)
		{
			e.CanExecute = _UCExperimentAnalysis != null && Experiment.Status == EExperimentStatus.Completed;
		}

		private void CommandBinding_Export_ExperimentData_Executed(object sender, ExecutedRoutedEventArgs e)
		{
			if (ConfigSettings.GetInstance().ExperimentSetting.CustomExport)
			{
				if (!File.Exists(ExperimentSetting.InternalCustomExportName))
				{
					MessageBox.Show(Utility.GetMainWindow(), Utility.GetMessage("msg_notset_customexportfile"));
					return;
				}
				string text = _UCExperimentAnalysis.ExportDefaultExperimentData();
				string text2 = ((_Experiment.CurrentSubset.GetQuantitativeProjectList().Count == 0) ? "0" : "1");
				Process.Start(ExperimentSetting.InternalCustomExportName, "\"" + text + "\" " + text2);
			}
			else
			{
				_UCExperimentAnalysis.ExportExperimentData();
			}
		}

		private void CommandBinding_Export_ExperimentTemplate_CanExecute(object sender, CanExecuteRoutedEventArgs e)
		{
			e.CanExecute = true;
		}

		private void CommandBinding_Export_ExperimentTemplate_Executed(object sender, ExecutedRoutedEventArgs e)
		{
			AddExperimentTemplateWindow addExperimentTemplateWindow = new AddExperimentTemplateWindow();
			addExperimentTemplateWindow.Owner = Utility.GetMainWindow();
			if (addExperimentTemplateWindow.ShowDialog() != true)
			{
				return;
			}
			string path = Utility.GetExperimentTemplatePath() + addExperimentTemplateWindow.file_name.Text + Experiment.FileTemplateDotExt;
			if (File.Exists(path))
			{
				if (MessageBox.Show(Utility.GetMainWindow(), Utility.GetMessage("msg_file_exist_cover"), Utility.GetMessage("Warning"), MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No) != MessageBoxResult.No)
				{
					if (File.GetAttributes(path).ToString().IndexOf("ReadOnly") != -1)
					{
						File.SetAttributes(path, FileAttributes.Normal);
					}
					Experiment.Simple_Name = addExperimentTemplateWindow.file_simple_name.Text;
					Experiment.TemplateRemarks = addExperimentTemplateWindow.file_remarks.Text;
					Experiment.Image = addExperimentTemplateWindow.ImageBytes;
					EPatientInfoSaveType savePatientInfo = ((addExperimentTemplateWindow.saveIndex == true) ? EPatientInfoSaveType.PatientInfo_Index : EPatientInfoSaveType.None);
					if (Experiment.SaveTemplate(path, false, savePatientInfo))
					{
						AddQuickExperimentToConfig(path, savePatientInfo);
						MessageBox.Show(Utility.GetMainWindow(), Utility.GetMessage("msg_quickExperiment_export_sussess"));
					}
				}
			}
			else
			{
				Experiment.Simple_Name = addExperimentTemplateWindow.file_simple_name.Text;
				Experiment.TemplateRemarks = addExperimentTemplateWindow.file_remarks.Text;
				Experiment.Image = addExperimentTemplateWindow.ImageBytes;
				EPatientInfoSaveType savePatientInfo2 = ((addExperimentTemplateWindow.saveIndex == true) ? EPatientInfoSaveType.PatientInfo_Index : EPatientInfoSaveType.None);
				if (Experiment.SaveTemplate(path, false, savePatientInfo2))
				{
					AddQuickExperimentToConfig(path, savePatientInfo2);
					MessageBox.Show(Utility.GetMainWindow(), Utility.GetMessage("msg_quickExperiment_export_sussess"));
				}
			}
		}

		private void AddQuickExperimentToConfig(string path, EPatientInfoSaveType savePatientInfo)
		{
			QuickExperimentData data = new QuickExperimentData();
			data.QuickExperimentName = path;
			data.IsShowInCanvas = true;
			data.Experiment = Experiment.CloneTemplate(Experiment, savePatientInfo);
			data.QuickDefaultPath = Experiment.DefaultPath;
			QuickExperimentData quickExperimentData = ConfigSettings.GetInstance().QuickExperimentDatas.Where((QuickExperimentData s) => s.QuickExperimentName.Equals(data.QuickExperimentName)).FirstOrDefault();
			if (quickExperimentData != null)
			{
				quickExperimentData.QuickExperimentName = path;
				quickExperimentData.IsShowInCanvas = true;
				quickExperimentData.Experiment = Experiment.CloneTemplate(Experiment, savePatientInfo);
				quickExperimentData.QuickDefaultPath = Experiment.DefaultPath;
			}
			else
			{
				data.Index = ((ConfigSettings.GetInstance().QuickExperimentDatas.Count > 0) ? (ConfigSettings.GetInstance().QuickExperimentDatas.Max((QuickExperimentData s) => s.Index) + 1) : 0);
				ConfigSettings.GetInstance().QuickExperimentDatas.Add(data);
			}
		}

		private void Command_Patient_Report_Manager_CanExecute(object sender, CanExecuteRoutedEventArgs e)
		{
			e.CanExecute = true;
		}

		private void Command_Patient_Report_Manager_Executed(object sender, ExecutedRoutedEventArgs e)
		{
			ExperimentPetientReportManageWindow experimentPetientReportManageWindow = new ExperimentPetientReportManageWindow();
			experimentPetientReportManageWindow.Owner = Utility.GetMainWindow();
			experimentPetientReportManageWindow.ShowDialog();
		}

		private void Command_Export_RDML_CanExecute(object sender, CanExecuteRoutedEventArgs e)
		{
			e.CanExecute = _UCExperimentAnalysis != null && Experiment.Status == EExperimentStatus.Completed;
		}

		private void Command_Export_RDML_Executed(object sender, ExecutedRoutedEventArgs e)
		{
			if (Experiment.Type == EProjectType.HRM || Experiment.Type == EProjectType.AD)
			{
				MessageBox.Show(Utility.GetMainWindow(), Utility.GetMessage("rdml_export_type_warning"), Utility.GetMessage("Warning"), MessageBoxButton.OK);
				return;
			}
			SaveFileDialog saveFileDialog = new SaveFileDialog();
			saveFileDialog.Title = Utility.GetMessage("rdml_export");
			saveFileDialog.Filter = string.Format("{0}{1}|*.{2}", RdmlExt, Utility.GetMessage("File"), RdmlExt);
			saveFileDialog.FileName = Experiment.Name;
			saveFileDialog.FilterIndex = 1;
			saveFileDialog.RestoreDirectory = true;
			saveFileDialog.DefaultExt = RdmlExt;
			if (saveFileDialog.ShowDialog() != true)
			{
				return;
			}
			RDML_v1_2_REC2 rDML_v1_2_REC = RDML_v1_2_REC2.CreateDocument();
			rdmlType rdmlType = rDML_v1_2_REC.rdml2.Append();
			rdmlType.version.Value = string.Concat(1.2);
			System.DateTime now = System.DateTime.Now;
			rdmlType.dateMade.Append().Value = new Altova.Types.DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second);
			rdmlType.dateUpdated.Append().Value = new Altova.Types.DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second);
			Dictionary<string, BasicOptionItem> dictionary = new Dictionary<string, BasicOptionItem>();
			List<string> list = new List<string>();
			foreach (Project item2 in (from s in Experiment.Wells
				where s.Project != null
				select s.Project).ToList())
			{
				foreach (TargetItem item3 in item2.Target.Items)
				{
					if (!string.IsNullOrEmpty(item3.Dye) && list.IndexOf(item3.Dye) < 0)
					{
						list.Add(item3.Dye);
						dyeType dyeType = rdmlType.dye.Append();
						dyeType.id.Value = item3.Dye;
					}
				}
			}
			foreach (Sample item4 in (from s in Experiment.Wells
				where s.Sample != null
				select s.Sample).ToList())
			{
				foreach (Well well in item4.Wells)
				{
					sampleType sampleType = rdmlType.sample.Append();
					sampleType.id.Value = well.CellName;
					switch (item4.Items[0].SampleType)
					{
					case SampleType.NTC:
						sampleType.type2.Append().Value = "ntc";
						break;
					case SampleType.Standard:
						sampleType.type2.Append().Value = "std";
						break;
					default:
						sampleType.type2.Append().Value = "unkn";
						break;
					}
					if (item4.Items[0].SampleType == SampleType.Standard)
					{
						quantityType quantityType = sampleType.quantity.Append();
						float result = 0f;
						float.TryParse(item4.Items[0].Property, out result);
						quantityType.value2.Append().Value = result;
						if (item4.Project.BasicInfo.Unit.Equals(Utility.GetMessage("default_unit")))
						{
							quantityType.unit.Append().Value = "cop";
						}
						else
						{
							quantityType.unit.Append().Value = "other";
						}
					}
				}
			}
			foreach (Project item5 in (from s in Experiment.Wells
				where s.Project != null
				select s.Project).ToList())
			{
				foreach (BasicOptionItem option in item5.BasicOption.Items)
				{
					string key = item5.BasicInfo.Name + "_" + option.TargetName;
					if (dictionary.Keys.Where((string s) => s.Equals(key)).ToList().Count == 0)
					{
						dictionary.Add(key, option);
						targetType targetType = rdmlType.target.Append();
						targetType.id.Value = item5.BasicInfo.Name + "_" + option.TargetName;
						targetType.type2.Append().Value = "toi";
						targetType.dyeId.Append().id.Value = item5.Target.Items.Where((TargetItem s) => s.Name == option.TargetName).FirstOrDefault().Dye;
						targetType.detectionLimit.Append().Value = (float)option.DetectionMin;
					}
				}
			}
			thermalCyclingConditionsType thermalCyclingConditionsType = rdmlType.thermalCyclingConditions.Append();
			thermalCyclingConditionsType.id.Value = "pcrProgram";
			thermalCyclingConditionsType.lidTemperature.Append().Value = Experiment.Device.HotlidSetTemperature;
			int num = 1;
			foreach (BaseSegment program in Experiment.Program.Programs)
			{
				Segment segment = program as Segment;
				MeltingSegment meltingSegment = program as MeltingSegment;
				int num2 = num;
				if (segment != null)
				{
					foreach (Step item6 in segment.Items)
					{
						stepType stepType = thermalCyclingConditionsType.step.Append();
						stepType.nr.Append().Value = num;
						temperatureType temperatureType = stepType.temperature.Append();
						temperatureType.temperature.Append().Value = (float)item6.Temperature;
						temperatureType.duration.Append().Value = item6.HoldMinute * 60 + item6.HoldSecond;
						if (item6.IsAdvProgram)
						{
							if (item6.IsUseRamp)
							{
								temperatureType.ramp.Append().Value = (float)item6.Ramp;
							}
							float num3 = (item6.IsTempVarUp ? 1 : (-1));
							temperatureType.temperatureChange.Append().Value = (float)item6.TempVarValue * num3;
							int num4 = (item6.IsTimeVarUp ? 1 : (-1));
							temperatureType.durationChange.Append().Value = item6.TimeVarValue * num4;
						}
						num++;
					}
					if (segment.Cycles > 1)
					{
						stepType stepType2 = thermalCyclingConditionsType.step.Append();
						stepType2.nr.Append().Value = num;
						loopType loopType = stepType2.loop.Append();
						loopType.goto2.Append().Value = num2;
						loopType.repeat.Append().Value = segment.Cycles;
						num++;
					}
				}
				else if (meltingSegment != null)
				{
					stepType stepType3 = thermalCyclingConditionsType.step.Append();
					stepType3.nr.Append().Value = num;
					gradientType gradientType = stepType3.gradient.Append();
					gradientType.highTemperature.Append().Value = (float)meltingSegment.StartTemp;
					gradientType.lowTemperature.Append().Value = (float)meltingSegment.EndTemp;
					gradientType.duration.Append().Value = meltingSegment.HoldTime;
					gradientType.ramp.Append().Value = float.Parse(meltingSegment.Rate.ToString());
					num++;
				}
			}
			experimentType experimentType = rdmlType.experiment.Append();
			experimentType.id.Value = Experiment.Name;
			runType runType = experimentType.run.Append();
			runType.id.Value = Experiment.Name ?? "";
			runType.instrument.Append().Value = Experiment.Device.DispalyModel;
			dataCollectionSoftwareType dataCollectionSoftwareType = runType.dataCollectionSoftware.Append();
			dataCollectionSoftwareType.name.Append().Value = Utility.GetMessage("MainWindowTitle");
			dataCollectionSoftwareType.version.Append().Value = Utility.GetProductFileVersion();

			if (Experiment.ExperimentSetting.AMPAlgorithm == EAMPAlgorithm.Default)
			{
				runType.backgroundDeterminationMethod.Append().Value = Utility.GetMessage("curve_amp_algorithm_log");
			}
			else
			{
				runType.backgroundDeterminationMethod.Append().Value = Utility.GetMessage("curve_amp_algorithm_subtraction");
			}
			pcrFormatType pcrFormatType = runType.pcrFormat.Append();
			pcrFormatType.rows.Append().Value = 8;
			if (Experiment.Device.Model == Device.DeviceModel_48P || Experiment.Device.Model == Device.DeviceModel_24P)
			{
				pcrFormatType.columns.Append().Value = 6;
			}
			else
			{
				pcrFormatType.columns.Append().Value = 12;
			}
			pcrFormatType.rowLabel.Append().Value = "ABC";
			pcrFormatType.columnLabel.Append().Value = "123";
			foreach (Well item7 in Experiment.Wells.Where((Well s) => s.Sample != null).ToList())
			{
				reactType reactType = runType.react.Append();
				reactType.id.Value = item7.ID + 1;
				reactType.sample.Append().id.Value = item7.CellName;
				foreach (SampleTargetItem item in item7.Sample.Items)
				{
					dataType dataType = reactType.data.Append();
					idReferencesType.MemberAttribute_id id = dataType.tar.Append().id;
					Func<KeyValuePair<string, BasicOptionItem>, bool> predicate = (KeyValuePair<string, BasicOptionItem> s) => s.Value.TargetName == item.TargetName;
					id.Value = dictionary.FirstOrDefault(predicate).Key;
					dataType.cq.Append().Value = (float)item.Result.CtValue;
					foreach (Dot item8 in item.Result.AMPCurve.CurvePoint)
					{
						dpAmpCurveType dpAmpCurveType = dataType.adp.Append();
						dpAmpCurveType.cyc.Append().Value = (float)item8.X;
						dpAmpCurveType.fluor.Append().Value = (float)item8.Y;
					}
					if (item7.Project.BasicInfo.Type != EProjectType.Melt)
					{
						continue;
					}
					MeltingTargetResult meltingTargetResult = item.Result as MeltingTargetResult;
					if (meltingTargetResult == null)
					{
						continue;
					}
					foreach (Dot item9 in meltingTargetResult.RawMeltingCurve.CurvePoint)
					{
						dpMeltingCurveType dpMeltingCurveType = dataType.mdp.Append();
						dpMeltingCurveType.tmp.Append().Value = (float)item9.X;
						dpMeltingCurveType.fluor.Append().Value = (float)item9.Y;
					}
				}
			}
			rDML_v1_2_REC.SaveToFile(rdml_file_inside_data_name, true);
			if (Utility.ZipFile(rdml_file_inside_data_name, saveFileDialog.FileName))
			{
				MessageBox.Show(Utility.GetMainWindow(), Utility.GetMessage("msg_data_export_sussess"));
			}
			File.Delete(rdml_file_inside_data_name);
		}

		private void Command_UpLoad_ExperimentDatat_CanExecute(object sender, CanExecuteRoutedEventArgs e)
		{
			e.CanExecute = _UCExperimentAnalysis != null && Experiment.Status == EExperimentStatus.Completed;
		}

		private void Command_UpLoad_ExperimentData_Executed(object sender, ExecutedRoutedEventArgs e)
		{
			try
			{
				string text = Utility.PostMoths(ConfigReader.GetInstance().GetUpLoad_UrlFromIni(), GetJsonParam());
				if (text.IndexOf("OK") > -1)
				{
					MessageBox.Show(Utility.GetMainWindow(), Utility.GetMessage("upLoad_ExperimentData_success"));
				}
				else
				{
					MessageBox.Show(Utility.GetMainWindow(), Utility.GetMessage("upLoad_ExperimentData_failed"));
				}
			}
			catch (Exception ex)
			{
				Log.WriteLine("Command_UpLoad_ExperimentData_Executed" + string.Format(ex.Message));
				MessageBox.Show(Utility.GetMainWindow(), ex.Message);
			}
		}

		private void Command_ExportByIndex_CanExecute(object sender, CanExecuteRoutedEventArgs e)
		{
			e.CanExecute = _UCExperimentAnalysis != null && Experiment.Status == EExperimentStatus.Completed;
		}

		private void Command_ExportByIndex_Executed(object sender, ExecutedRoutedEventArgs e)
		{
			List<string> list = (from s in _Experiment.Wells
				where s.Sample != null && s.Sample.PatientInfo.ID != null
				select s.Sample.PatientInfo.ID).Distinct().ToList();
			Dictionary<string, List<string>> dictionary = new Dictionary<string, List<string>>();
			if (_Experiment.Wells.Where((Well s) => s.Sample != null && s.Sample.PatientInfo.ID == null).Count() > 0)
			{
				dictionary.Add("emptyIndex", new List<string> { null });
			}
			foreach (string item in list)
			{
				if (item.Length > 12)
				{
					string key = item.Substring(0, 13);
					if (dictionary.ContainsKey(key))
					{
						dictionary[key].Add(item);
						continue;
					}
					dictionary.Add(key, new List<string> { item });
				}
				else
				{
					dictionary.Add(item, new List<string> { item });
				}
			}
			try
			{
				foreach (string key2 in dictionary.Keys)
				{
					_UCExperimentAnalysis.ExportExperimentDataIIndexClassify(key2, dictionary[key2]);
				}
			}
			catch (Exception ex)
			{
				Log.WriteLine("Command_ExportByIndex_Executed" + string.Format(ex.Message));
				MessageBox.Show(Utility.GetMainWindow(), Utility.GetMessage("msg_data_export_failed"));
			}
			finally
			{
				MessageBox.Show(Utility.GetMainWindow(), Utility.GetMessage("msg_data_export_sussess"));
			}
		}

		private bool HasStandardData()
		{
			if (Experiment.Status == EExperimentStatus.Completed)
			{
				return Experiment.CurrentSubset.GetQuantitativeProjectList().Count > 0;
			}
			return false;
		}

		private void CallLoadSubsetStandardCurveWindow(List<string> prjNameList = null)
		{
			LoadSubsetStandardCurveWindow loadSubsetStandardCurveWindow = new LoadSubsetStandardCurveWindow();
			loadSubsetStandardCurveWindow.Owner = Utility.GetMainWindow();
			loadSubsetStandardCurveWindow.Subset = Experiment.CurrentSubset;
			loadSubsetStandardCurveWindow.StandardProjectName = prjNameList;
			loadSubsetStandardCurveWindow.SetBinding(LoadSubsetStandardCurveWindow.IsDecryptProperty, new Binding("IsDecrypt")
			{
				Source = this
			});
			if (loadSubsetStandardCurveWindow.ShowDialog() == true)
			{
				_IsModified = true;
			}
		}

		private void CommandBinding_Save_StandardData_CanExecute(object sender, CanExecuteRoutedEventArgs e)
		{
			e.CanExecute = _UCExperimentAnalysis != null && _UCExperimentAnalysis.HasStandardCurve();
		}

		private void CommandBinding_Save_StandardData_Executed(object sender, ExecutedRoutedEventArgs e)
		{
			IList<Project> quantitativeProjectList = Experiment.CurrentSubset.GetQuantitativeProjectList();
			SaveStandardCurveWindow saveStandardCurveWindow = new SaveStandardCurveWindow();
			saveStandardCurveWindow.Owner = Utility.GetMainWindow();
			saveStandardCurveWindow.SetSubset(Experiment.CurrentSubset);
			saveStandardCurveWindow.SetProjects(quantitativeProjectList);
			saveStandardCurveWindow.ShowDialog();
		}

		private void Command_Load_StandardData_CanExecute(object sender, CanExecuteRoutedEventArgs e)
		{
			e.CanExecute = HasStandardData();
		}

		private void Command_Load_StandardData_Executed(object sender, ExecutedRoutedEventArgs e)
		{
			CallLoadSubsetStandardCurveWindow();
		}

		private void Command_Management_StandardData_CanExecute(object sender, CanExecuteRoutedEventArgs e)
		{
			e.CanExecute = true;
		}

		private void Command_Management_StandardData_Executed(object sender, ExecutedRoutedEventArgs e)
		{
			StandardCurveManageWindow standardCurveManageWindow = new StandardCurveManageWindow();
			standardCurveManageWindow.Owner = Utility.GetMainWindow();
			standardCurveManageWindow.ShowDialog();
		}

		private void CommandBinding_Copy_CanExecute(object sender, CanExecuteRoutedEventArgs e)
		{
			if (TabControlExperiment.SelectedItem == TabItemSampleInfo && _UCSampleInfo != null)
			{
				e.CanExecute = _UCSampleInfo.UCPatientInfo.CanCopy();
			}
		}

		private void CommandBinding_Copy_Executed(object sender, ExecutedRoutedEventArgs e)
		{
			if (TabControlExperiment.SelectedItem == TabItemSampleInfo && _UCSampleInfo != null)
			{
				_UCSampleInfo.UCPatientInfo.CopySelectedCellsToClipboard();
			}
		}

		private void CommandBinding_Paste_CanExecute(object sender, CanExecuteRoutedEventArgs e)
		{
			if (TabControlExperiment.SelectedItem == TabItemSampleInfo && _UCSampleInfo != null)
			{
				e.CanExecute = _UCSampleInfo.UCPatientInfo.CanPaste();
			}
		}

		private void CommandBinding_Paste_Executed(object sender, ExecutedRoutedEventArgs e)
		{
			if (TabControlExperiment.SelectedItem == TabItemSampleInfo && _UCSampleInfo != null)
			{
				_UCSampleInfo.UCPatientInfo.PasteClipboardDataToCells();
			}
			_IsModified = true;
		}

		private void CommandBinding_Delete_CanExecute(object sender, CanExecuteRoutedEventArgs e)
		{
			if (TabControlExperiment.SelectedItem == TabItemSampleInfo)
			{
				if (_UCSampleInfo != null)
				{
					e.CanExecute = _UCSampleInfo.UCPatientInfo.CommandBindingDelete_CanExecute();
				}
			}
			else if (_UCWellEdit != null)
			{
				e.CanExecute = IsDecrypt && _UCWellEdit.IsSelectedWell();
			}
		}

		private void CommandBinding_Delete_Executed(object sender, ExecutedRoutedEventArgs e)
		{
			if (TabControlExperiment.SelectedItem == TabItemSampleInfo)
			{
				if (_UCSampleInfo != null)
				{
					_UCSampleInfo.UCPatientInfo.CommandBindingDelete_Executed();
				}
			}
			else if (_UCWellEdit != null)
			{
				_UCWellEdit.UpdataSelectedProject(null);
			}
			_IsModified = true;
		}

		private void CommandBinding_Auto_Standard_CanExecute(object sender, CanExecuteRoutedEventArgs e)
		{
			if (_UCWellEdit != null)
			{
				e.CanExecute = IsDecrypt && _UCWellEdit.CanAutoStandard();
			}
		}

		private void CommandBinding_Auto_Standard_Executed(object sender, ExecutedRoutedEventArgs e)
		{
			if (_UCWellEdit != null && _UCWellEdit.AutoStandart())
			{
				_IsModified = true;
			}
		}

		private void CommandBinding_AutoIndex_CanExecute(object sender, CanExecuteRoutedEventArgs e)
		{
			if (_UCSampleInfo != null)
			{
				e.CanExecute = _UCSampleInfo.UCPatientInfo.ItemsSource != null && _UCSampleInfo.UCPatientInfo.ItemsSource.Count > 0 && IsDecrypt;
			}
		}

		private void CommandBinding_AutoIndex_Executed(object sender, ExecutedRoutedEventArgs e)
		{
			_UCSampleInfo.UCPatientInfo.dataGrid.CommitEdit();
			
			AutoIndexWindow autoIndexWindow = new AutoIndexWindow();
			autoIndexWindow.OnAutoIndexChanged += win_OnAutoIndexChanged;
			autoIndexWindow.AllSamples = _UCSampleInfo.UCPatientInfo.dataGrid.ItemsSource as List<Sample>;

			if (_UCSampleInfo.IsInfoForWellSelected())
			{
				List<Sample> samples = (from s in _UCSampleInfo.UCPatientInfoForWell.SelectedWells
					where s.Sample != null
					select s.Sample).Distinct().ToList();
				samples = GetSortedSamples(samples);
				autoIndexWindow.SelectSamples = samples;
			}
			else
			{
				autoIndexWindow.SelectSamples = _UCSampleInfo.UCPatientInfo.dataGrid.SelectedCells.Select((DataGridCellInfo s) => s.Item).Distinct().Cast<Sample>()
					.ToList();
			}
			autoIndexWindow.Owner = Utility.GetMainWindow();
			autoIndexWindow.ShowDialog();
			if (autoIndexWindow.IsModify)
			{
				_IsModified = true;
			}
		}

		private void win_OnAutoIndexChanged(object sender, EventArgs e)
		{
			_UCSampleInfo.UCPatientInfoForWell.RefreshInfo();
		}

		private void CommandBinding_PatientExport_CanExecute(object sender, CanExecuteRoutedEventArgs e)
		{
			e.CanExecute = false;
		}

		private void CommandBinding_PatientExport_Executed(object sender, ExecutedRoutedEventArgs e)
		{
		}

		private void CommandBinding_PatientImport_CanExecute(object sender, CanExecuteRoutedEventArgs e)
		{
			e.CanExecute = IsDecrypt;
		}

		private void CommandBinding_PatientImport_Executed(object sender, ExecutedRoutedEventArgs e)
		{
			PatientImportWindow patientImportWindow = new PatientImportWindow();
			patientImportWindow.DataContext = Experiment;
			patientImportWindow.Owner = Utility.GetMainWindow();
			bool? flag = patientImportWindow.ShowDialog();
			if (flag != true || !flag.HasValue || patientImportWindow.allData.Count <= 0 || patientImportWindow.table.Count <= 0)
			{
				return;
			}
			List<Sample> list = _UCSampleInfo.UCPatientInfo.dataGrid.ItemsSource as List<Sample>;
			if (list == null || list.Count == 0)
			{
				return;
			}
			List<string[]> allData = patientImportWindow.allData;
			int num = 0;
			foreach (KeyValuePair item in patientImportWindow.table)
			{
				int result = -1;
				int.TryParse(item.Value.ToString(), out result);
				switch (item.Key.ToString())
				{
				case "WellCell.Well.Sample.PatientInfo.ID":
				{
					for (int num10 = 0; num10 < list.Count; num10++)
					{
						Sample sample15 = list[num10];
						if (num10 < allData.Count)
						{
							sample15.PatientInfo.ID = GetPatientInfo(result, allData[num10]);
						}
					}
					break;
				}
				case "WellCell.Well.Sample.PatientInfo.Name":
				{
					for (int num2 = 0; num2 < list.Count; num2++)
					{
						Sample sample7 = list[num2];
						if (num2 < allData.Count)
						{
							sample7.PatientInfo.Name = GetPatientInfo(result, allData[num2]);
						}
					}
					break;
				}
				case "WellCell.Well.Sample.PatientInfo.Sex":
				{
					for (int num6 = 0; num6 < list.Count; num6++)
					{
						Sample sample11 = list[num6];
						if (num6 < allData.Count)
						{
							sample11.PatientInfo.Sex = GetPatientInfo(result, allData[num6]);
						}
					}
					break;
				}
				case "WellCell.Well.Sample.PatientInfo.Age":
				{
					for (int k = 0; k < list.Count; k++)
					{
						Sample sample3 = list[k];
						if (k < allData.Count)
						{
							sample3.PatientInfo.Age = GetPatientInfo(result, allData[k]);
						}
					}
					break;
				}
				case "WellCell.Well.Sample.PatientInfo.Specimen":
				{
					for (int num8 = 0; num8 < list.Count; num8++)
					{
						Sample sample13 = list[num8];
						if (num8 < allData.Count)
						{
							sample13.PatientInfo.Specimen = GetPatientInfo(result, allData[num8]);
						}
					}
					break;
				}
				case "WellCell.Well.Sample.PatientInfo.SpecimenDate":
				{
					for (int num4 = 0; num4 < list.Count; num4++)
					{
						Sample sample9 = list[num4];
						if (num4 < allData.Count)
						{
							sample9.PatientInfo.SpecimenDate = GetPatientInfo(result, allData[num4]);
						}
					}
					break;
				}
				case "WellCell.Well.Sample.PatientInfo.Doctor":
				{
					for (int m = 0; m < list.Count; m++)
					{
						Sample sample5 = list[m];
						if (m < allData.Count)
						{
							sample5.PatientInfo.Doctor = GetPatientInfo(result, allData[m]);
						}
					}
					break;
				}
				case "WellCell.Well.Sample.PatientInfo.Office":
				{
					for (int j = 0; j < list.Count; j++)
					{
						Sample sample2 = list[j];
						if (j < allData.Count)
						{
							sample2.PatientInfo.Office = GetPatientInfo(result, allData[j]);
						}
					}
					break;
				}
				case "WellCell.Well.Sample.PatientInfo.Diagnosis":
				{
					for (int num9 = 0; num9 < list.Count; num9++)
					{
						Sample sample14 = list[num9];
						if (num9 < allData.Count)
						{
							sample14.PatientInfo.Diagnosis = GetPatientInfo(result, allData[num9]);
						}
					}
					break;
				}
				case "WellCell.Well.Sample.PatientInfo.CaseID":
				{
					for (int num7 = 0; num7 < list.Count; num7++)
					{
						Sample sample12 = list[num7];
						if (num7 < allData.Count)
						{
							sample12.PatientInfo.CaseID = GetPatientInfo(result, allData[num7]);
						}
					}
					break;
				}
				case "WellCell.Well.Sample.PatientInfo.BedID":
				{
					for (int num5 = 0; num5 < list.Count; num5++)
					{
						Sample sample10 = list[num5];
						if (num5 < allData.Count)
						{
							sample10.PatientInfo.BedID = GetPatientInfo(result, allData[num5]);
						}
					}
					break;
				}
				case "WellCell.Well.Sample.PatientInfo.InPatientID":
				{
					for (int num3 = 0; num3 < list.Count; num3++)
					{
						Sample sample8 = list[num3];
						if (num3 < allData.Count)
						{
							sample8.PatientInfo.InPatientID = GetPatientInfo(result, allData[num3]);
						}
					}
					break;
				}
				case "WellCell.Well.Sample.PatientInfo.OutPatientID":
				{
					for (int n = 0; n < list.Count; n++)
					{
						Sample sample6 = list[n];
						if (n < allData.Count)
						{
							sample6.PatientInfo.OutPatientID = GetPatientInfo(result, allData[n]);
						}
					}
					break;
				}
				case "WellCell.Well.Sample.PatientInfo.Remark":
				{
					for (int l = 0; l < list.Count; l++)
					{
						Sample sample4 = list[l];
						if (l < allData.Count)
						{
							sample4.PatientInfo.Remark = GetPatientInfo(result, allData[l]);
						}
					}
					break;
				}
				case "":
				{
					for (int i = 0; i < list.Count; i++)
					{
						Sample sample = list[i];
						if (i < allData.Count && num < sample.PatientInfo.CustomData.Count)
						{
							sample.PatientInfo.CustomData[num] = GetPatientInfo(result, allData[i]);
						}
					}
					num++;
					break;
				}
				}
			}
		}

		private string GetPatientInfo(int index, string[] datas)
		{
			string result = string.Empty;
			if (index > -1 && datas.Length > index)
			{
				result = datas[index];
			}
			return result;
		}

		private void Command_GridColumn_Edit_CanExecute(object sender, CanExecuteRoutedEventArgs e)
		{
			e.CanExecute = (TabControlExperiment.SelectedItem == TabItemSampleInfo && IsDecrypt) || (TabControlExperiment.SelectedItem == TabItemExperimentRun && IsDecrypt) || (TabControlExperiment.SelectedItem == TabItemExperimentAnalysis && IsDecrypt);
		}

		private void Command_GridColumn_Edit_Executed(object sender, ExecutedRoutedEventArgs e)
		{
			GridColumnEditWindow gridColumnEditWindow = new GridColumnEditWindow();
			gridColumnEditWindow.Owner = Utility.GetMainWindow();
			GridColumns dataContext = Experiment.GridColumns.Clone();
			gridColumnEditWindow.DataContext = dataContext;
			if (gridColumnEditWindow.ShowDialog() == true)
			{
				GridColumns gridColumns = gridColumnEditWindow.DataContext as GridColumns;
				if (gridColumns != null)
				{
					Experiment.GridColumns = gridColumns;
				}
				_IsModified = true;
			}
		}

		private void Command_Experiment_Set_CanExecute(object sender, CanExecuteRoutedEventArgs e)
		{
			e.CanExecute = IsDecrypt;
		}

		private void Command_Experiment_Set_Executed(object sender, ExecutedRoutedEventArgs e)
		{
			ExperimentSettingWindow experimentSettingWindow = new ExperimentSettingWindow();
			experimentSettingWindow.Owner = Utility.GetMainWindow();
			ExperimentSetting experimentSetting = Experiment.ExperimentSetting.Clone();
			experimentSettingWindow.viewConfig(experimentSetting, Experiment.Type);
			if (experimentSettingWindow.ShowDialog() == true)
			{
				if (Experiment.ExperimentSetting.AMPAlgorithm != experimentSetting.AMPAlgorithm)
				{
					Experiment.ExperimentSetting.Copy(experimentSetting);
					SetThreshold();
				}
				else
				{
					Experiment.ExperimentSetting.Copy(experimentSetting);
				}
				_IsModified = true;
				Buttoncontrol();
			}
		}

		private void CommandBinding_DisplayChannel_CanExecute(object sender, CanExecuteRoutedEventArgs e)
		{
			int result = 0;
			if (e.Parameter != null)
			{
				int.TryParse(e.Parameter.ToString(), out result);
			}
			e.CanExecute = ChannelCanExecute(result);
			if (!e.CanExecute)
			{
				SetChannelStatus(result, false);
			}
		}

		private void CommandBinding_DisplayChannel_Executed(object sender, ExecutedRoutedEventArgs e)
		{
		}

		private bool ChannelCanExecute(int channelNo)
		{
			return channelList.Contains(channelNo);
		}

		private void CommandBinding_Start_CanExecute(object sender, CanExecuteRoutedEventArgs e)
		{
			bool flag = Experiment.Device.OperationEnable && !string.IsNullOrEmpty(Experiment.Device.Series) && Experiment.Status != EExperimentStatus.Completed && Experiment.Program != null;
			if (flag && Experiment.Status == EExperimentStatus.Running)
			{
				flag = flag && (!Experiment.Device.IsIncludePreheatSegment || Experiment.Device.PreTemperatureArrive);
			}
			e.CanExecute = flag;
		}

		private void CommandBinding_Start_Executed(object sender, ExecutedRoutedEventArgs e)
		{
			switch (Experiment.Status)
			{
			case EExperimentStatus.NotRunning:
			case EExperimentStatus.Interrupt:
				if (!Experiment.Program.IsContainsPreHeatSegment())
				{
					if (MessageBox.Show(Utility.GetMainWindow(), Utility.GetMessage("msg_experiment_run_question"), Utility.GetMessage("Warning"), MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Yes) == MessageBoxResult.No)
					{
						break;
					}
					if (!Experiment.UseHotBonnet && Experiment.Device.Model != Device.DeviceModel_40P)
					{
						switch (MessageBox.Show(Utility.GetMainWindow(), Utility.GetMessage("msg_experiment_not_use_hotlid"), Utility.GetMessage("msg_experiment_use_hotlid_tip"), MessageBoxButton.YesNoCancel, MessageBoxImage.Exclamation, MessageBoxResult.Yes))
						{
						case MessageBoxResult.Yes:
							Experiment.UseHotBonnet = true;
							break;
						case MessageBoxResult.Cancel:
							return;
						}
					}
				}
				Experiment.Run();
				if (_UCExperimentRun != null)
				{
					_UCExperimentRun.InitChartInfo();
					_UCExperimentRun.SetRunStatus();
				}
				break;
			case EExperimentStatus.Running:
				if (Experiment.Program.IsContainsPreHeatSegment() && StartText == Utility.GetMessage("start"))
				{
					if (MessageBox.Show(Utility.GetMainWindow(), Utility.GetMessage("msg_experiment_run_question"), Utility.GetMessage("Warning"), MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Yes) == MessageBoxResult.No)
					{
						break;
					}
					if (!Experiment.UseHotBonnet)
					{
						switch (MessageBox.Show(Utility.GetMainWindow(), Utility.GetMessage("msg_experiment_not_use_hotlid"), Utility.GetMessage("msg_experiment_use_hotlid_tip"), MessageBoxButton.YesNoCancel, MessageBoxImage.Exclamation, MessageBoxResult.Yes))
						{
						case MessageBoxResult.Yes:
							Experiment.UseHotBonnet = true;
							break;
						case MessageBoxResult.Cancel:
							return;
						}
					}
					Experiment.ProgramRun();
					StartText = Utility.GetMessage("interrupt");
				}
				else if (MessageBox.Show(Utility.GetMainWindow(), string.Format(Utility.GetMessage("msg_experiment_interrupt"), Experiment.Name), Utility.GetMessage("Warning"), MessageBoxButton.YesNo, MessageBoxImage.Exclamation, MessageBoxResult.No) == MessageBoxResult.Yes)
				{
					Experiment.Stop();
				}
				break;
			}
		}

		private void btnAnalysis_Click(object sender, RoutedEventArgs e)
		{
			Utility.GetMainWindow().Cursor = Cursors.Wait;
			btnAnalysis.IsEnabled = false;
			Utility.DoEvents();
			if (_UCExperimentAnalysis.ValidateParamter())
			{
				ExperimentAnalysis(false);
			}
			btnAnalysis.IsEnabled = true;
			Utility.GetMainWindow().Cursor = Cursors.Arrow;
		}

		private void CommandBinding_Subset_Edit_CanExecute(object sender, CanExecuteRoutedEventArgs e)
		{
			e.CanExecute = IsDecrypt;
		}

		private void CommandBinding_Subset_Edit_Executed(object sender, ExecutedRoutedEventArgs e)
		{
			SubsetEditWindow subsetEditWindow = new SubsetEditWindow();
			subsetEditWindow.Owner = Utility.GetMainWindow();
			subsetEditWindow.DataContext = Experiment;
			subsetEditWindow.ShowDialog();
			if (_UCExperimentAnalysis != null)
			{
				_UCExperimentAnalysis.RefreshSubset();
			}
			_IsModified = true;
		}

		private void Command_Subset_BasicOption_CanExecute(object sender, CanExecuteRoutedEventArgs e)
		{
			e.CanExecute = Experiment.CurrentSubset.Wells.Count > 0;
		}

		private void Command_Subset_BasicOption_Executed(object sender, ExecutedRoutedEventArgs e)
		{
			if (_UCExperimentAnalysis != null)
			{
				SubsetParamterWindow subsetParamterWindow = new SubsetParamterWindow();
				subsetParamterWindow.SetBinding(SubsetParamterWindow.IsDecryptProperty, new Binding("IsDecrypt")
				{
					Source = this
				});
				subsetParamterWindow.Title = Utility.GetMessage("PrjM_ParamterSetting");
				subsetParamterWindow.Owner = Utility.GetMainWindow();
				subsetParamterWindow.SubsetParamterType = ESubsetParamterType.BasicOption;
				subsetParamterWindow.Subset = Experiment.CurrentSubset;
				subsetParamterWindow.SelectedWells = _UCExperimentAnalysis.GetSelectedWells();
				if (subsetParamterWindow.ShowDialog() == true)
				{
					_IsModified = true;
				}
			}
		}

		private void Command_Subset_Detection_CanExecute(object sender, CanExecuteRoutedEventArgs e)
		{
			if (_UCExperimentAnalysis == null)
			{
				return;
			}
			List<Well> selectedWells = _UCExperimentAnalysis.GetSelectedWells();
			if (selectedWells.Count <= 0)
			{
				return;
			}
			List<Project> list = (from s in selectedWells
				select s.Project into s
				where s != null
				select s).Distinct().ToList();
			foreach (Project item in list)
			{
				Subset.SubsetParamter subsetParamter = Experiment.CurrentSubset.GetSubsetParamter(item);
				if (subsetParamter != null && subsetParamter.BasicOption.Items.Where((BasicOptionItem s) => s.AnalysisType == EAnalysisType.ANALYSIS_QUANTITATIVE).Count() > 0)
				{
					e.CanExecute = true;
					break;
				}
			}
		}

		private void Command_Subset_Detection_Executed(object sender, ExecutedRoutedEventArgs e)
		{
			if (_UCExperimentAnalysis != null)
			{
				SubsetParamterWindow subsetParamterWindow = new SubsetParamterWindow();
				subsetParamterWindow.SetBinding(SubsetParamterWindow.IsDecryptProperty, new Binding("IsDecrypt")
				{
					Source = this
				});
				subsetParamterWindow.Title = Utility.GetMessage("Prj_QuantitativeRange");
				subsetParamterWindow.Owner = Utility.GetMainWindow();
				subsetParamterWindow.SubsetParamterType = ESubsetParamterType.Detection;
				subsetParamterWindow.Subset = Experiment.CurrentSubset;
				subsetParamterWindow.SelectedWells = _UCExperimentAnalysis.GetSelectedWells();
				if (subsetParamterWindow.ShowDialog() == true)
				{
					_IsModified = true;
				}
			}
		}

		private void Command_Subset_Rule_CanExecute(object sender, CanExecuteRoutedEventArgs e)
		{
			e.CanExecute = Experiment.CurrentSubset.Wells.Count > 0;
		}

		private void Command_Subset_Rule_Executed(object sender, ExecutedRoutedEventArgs e)
		{
			if (_UCExperimentAnalysis != null)
			{
				SubsetParamterWindow subsetParamterWindow = new SubsetParamterWindow();
				subsetParamterWindow.SetBinding(SubsetParamterWindow.IsDecryptProperty, new Binding("IsDecrypt")
				{
					Source = this
				});
				subsetParamterWindow.Title = Utility.GetMessage("Prj_RuleConclusion");
				subsetParamterWindow.Width = 800.0;
				subsetParamterWindow.Height = 700.0;
				subsetParamterWindow.Owner = Utility.GetMainWindow();
				subsetParamterWindow.SubsetParamterType = ESubsetParamterType.Rule;
				subsetParamterWindow.Subset = Experiment.CurrentSubset;
				subsetParamterWindow.SelectedWells = _UCExperimentAnalysis.GetSelectedWells();
				if (subsetParamterWindow.ShowDialog() == true)
				{
					_IsModified = true;
				}
			}
		}

		private void Command_Subset_CrossTalk_CanExecute(object sender, CanExecuteRoutedEventArgs e)
		{
			e.CanExecute = (from s in Experiment.CurrentSubset.Wells.Where((Well s) => s.Project != null).Distinct()
				where s.Project.BasicOption.Items.Select((BasicOptionItem s1) => s1.ChannelNo).Count() > 1
				select s).Count() > 0;
		}

		private void Command_Subset_CrossTalk_Executed(object sender, ExecutedRoutedEventArgs e)
		{
			if (_UCExperimentAnalysis != null)
			{
				SubsetParamterWindow subsetParamterWindow = new SubsetParamterWindow();
				subsetParamterWindow.SetBinding(SubsetParamterWindow.IsDecryptProperty, new Binding("IsDecrypt")
				{
					Source = this
				});
				subsetParamterWindow.Title = Utility.GetMessage("Prj_Crosstalk");
				subsetParamterWindow.Owner = Utility.GetMainWindow();
				subsetParamterWindow.SubsetParamterType = ESubsetParamterType.CrossTalk;
				subsetParamterWindow.Subset = Experiment.CurrentSubset;
				subsetParamterWindow.SelectedWells = _UCExperimentAnalysis.GetSelectedWells();
				if (subsetParamterWindow.ShowDialog() == true)
				{
					_IsModified = true;
				}
			}
		}

		private void Command_Subset_Rename_CanExecute(object sender, CanExecuteRoutedEventArgs e)
		{
			e.CanExecute = true;
		}

		private void Command_Subset_Rename_Executed(object sender, ExecutedRoutedEventArgs e)
		{
			SubsetGenoRenameWindow subsetGenoRenameWindow = new SubsetGenoRenameWindow();
			subsetGenoRenameWindow.Owner = Utility.GetMainWindow();
			subsetGenoRenameWindow.IsDecrypt = IsDecrypt;
			subsetGenoRenameWindow.Subset = Experiment.CurrentSubset;
			subsetGenoRenameWindow.SetDataResource();
			if (subsetGenoRenameWindow.ShowDialog() == true)
			{
				_IsModified = true;
			}
		}

		private void Device_RunErrorEvent(object sender, EventArgs e)
		{
			if (Experiment.Status == EExperimentStatus.Completed)
			{
				return;
			}
			if (Experiment.Device.RunError != 0)
			{
				Experiment.Stop();
			}
			StringBuilder stringBuilder = new StringBuilder();
			switch (Experiment.Device.RunError)
			{
			case RunningError.DeviceConnectError:
				stringBuilder.AppendLine(Utility.GetMessage("msg_DeviceConnectError"));
				break;
			case RunningError.CommunicationError:
				stringBuilder.AppendLine(Utility.GetMessage("msg_CommunicationError"));
				break;
			case RunningError.CloseHotlidError:
				stringBuilder.AppendLine(Utility.GetMessage("msg_CloseHotlidError"));
				break;
			case RunningError.SliderNotClose:
				stringBuilder.AppendLine(Utility.GetMessage("msg_SliderNotClose"));
				break;
			case RunningError.OpenHotlidError:
				MessageBox.Show(Utility.GetMainWindow(), Utility.GetMessage("msg_OpenHotlidError"));
				Experiment.RefreshStatus();
				break;
			case RunningError.SendCommandError:
				stringBuilder.AppendLine(Utility.GetMessage("msg_SendCommandError"));
				break;
			case RunningError.BlockOverTemperatureError:
				stringBuilder.AppendLine(Utility.GetMessage("msg_BlockOverTemperatureError"));
				break;
			case RunningError.HotlidOverTemperatureError:
				stringBuilder.AppendLine(Utility.GetMessage("msg_HotlidOverTemperatureError"));
				break;
			case RunningError.BlockTemperatureUpDownError:
				stringBuilder.AppendLine(Utility.GetMessage("msg_BlockTemperatureUpDownError"));
				break;
			case RunningError.HotlidTemperatureRiseError:
				stringBuilder.AppendLine(Utility.GetMessage("msg_HotlidTemperatureRiseError"));
				break;
			}
			if (stringBuilder.Length <= 0)
			{
				return;
			}
			BackgroundWorker backgroundWorker = new BackgroundWorker();
			backgroundWorker.DoWork += bw_DoWork;
			backgroundWorker.RunWorkerAsync();
			stringBuilder.AppendLine();
			stringBuilder.AppendLine(string.Format(Utility.GetMessage("msg_BreakPoint"), Experiment.Device.BreakPoint));
			do
			{
				if (MessageBox.Show(Utility.GetMainWindow(), stringBuilder.ToString(), Utility.GetMessage("Warning"), MessageBoxButton.YesNo, MessageBoxImage.Exclamation, MessageBoxResult.Yes) == MessageBoxResult.Yes)
				{
					Experiment.Continue();
					return;
				}
			}
			while (MessageBox.Show(Utility.GetMainWindow(), string.Format(Utility.GetMessage("msg_Experiment_Break"), Experiment.Name), Utility.GetMessage("Warning"), MessageBoxButton.YesNo, MessageBoxImage.Exclamation, MessageBoxResult.No) != MessageBoxResult.Yes);
			Experiment.RefreshStatus();
		}

		private void bw_DoWork(object sender, DoWorkEventArgs e)
		{
			for (int i = 0; i < 5; i++)
			{
				MessageBeep(uint.MaxValue);
				Thread.Sleep(500);
			}
		}

		private void Device_OperationEnableEvent(object sender, EventArgs e)
		{
			base.Dispatcher.BeginInvoke((Action)delegate
			{
				CommandManager.InvalidateRequerySuggested();
			});
		}

		private void Device_RawDataChangedEvent(object sender, EventArgs e)
		{
			base.Dispatcher.BeginInvoke((Action)delegate
			{
				ExperimentAnalysis();
			});
		}

		private void Experiment_Event(object sender, EventArgs e)
		{
			PropertyChangedEventArgsEx propertyChangedEventArgsEx = e as PropertyChangedEventArgsEx;
			if (propertyChangedEventArgsEx == null)
			{
				return;
			}
			string property = propertyChangedEventArgsEx.PropertyName;
			base.Dispatcher.BeginInvoke((Action)delegate
			{
				Experiment experiment = sender as Experiment;
				if (experiment != null)
				{
					if (property == "Program")
					{
						RefreshStartText();
						ProgramChanged(experiment.Program);
					}
					else if (property == "Status")
					{
						RefreshStartText();
						if (experiment.Status == EExperimentStatus.Completed)
						{
							if (experiment.HasEnoughData())
							{
								if (string.IsNullOrEmpty(Experiment.FilePath) || File.Exists(Experiment.FilePath))
								{
									SaveExperiment(true);
								}
								else
								{
									SaveExperiment();
								}
								TabControlExperiment.SelectedItem = TabItemExperimentAnalysis;
								if (ConfigSettings.GetInstance().BasicSetting.AutoSaveOption == EAutoSaveType.AutoEnd)
								{
									BackgroundWorker backgroundWorker = new BackgroundWorker();
									backgroundWorker.DoWork += worker_DoWork;
									backgroundWorker.RunWorkerCompleted += worker_RunWorkerCompleted;
									backgroundWorker.RunWorkerAsync();
								}
							}
							else
							{
								experiment.Status = EExperimentStatus.NotRunning;
							}
						}
						RaiseExperimentStatusChanged();
					}
				}
			});
		}

		private void SetThreshold(bool isSave = false, bool isLoad = false)
		{
			List<Well> wells = _Experiment.CurrentSubset.Wells;
			IList<Project> list = (from s in wells
				select s.Project into s
				where s != null
				select s).Distinct().ToList();
			switch (_Experiment.ExperimentSetting.AMPAlgorithm)
			{
			case EAMPAlgorithm.Default:
			{
				foreach (Project item in list)
				{
					Subset.SubsetParamter subsetParamter2 = _Experiment.CurrentSubset.GetSubsetParamter(item);
					foreach (BasicOptionItem item2 in subsetParamter2.BasicOption.Items)
					{
						if (isSave)
						{
							item2.ThresholdDefault = item2.Threshold;
							continue;
						}
						if (isLoad)
						{
							item2.Threshold = item2.ThresholdDefault;
							continue;
						}
						item2.ThresholdSubtraction = item2.Threshold;
						item2.Threshold = item2.ThresholdDefault;
					}
				}
				break;
			}
			case EAMPAlgorithm.Subtraction:
			{
				foreach (Project item3 in list)
				{
					Subset.SubsetParamter subsetParamter = _Experiment.CurrentSubset.GetSubsetParamter(item3);
					foreach (BasicOptionItem item4 in subsetParamter.BasicOption.Items)
					{
						if (isSave)
						{
							item4.ThresholdSubtraction = item4.Threshold;
							continue;
						}
						if (isLoad)
						{
							item4.Threshold = item4.ThresholdSubtraction;
							continue;
						}
						item4.ThresholdDefault = item4.Threshold;
						item4.Threshold = item4.ThresholdSubtraction;
					}
				}
				break;
			}
			}
		}

		private string GetJsonParam()
		{
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append("{");
			addJsonItem(stringBuilder, "testname", Experiment.Name);
			addJsonItem(stringBuilder, "stime", Experiment.Device.StartTime.ToString(Utility.GetMessage("default_datetimeformat")));
			addJsonItem(stringBuilder, "etime", Experiment.Device.StopTime.ToString(Utility.GetMessage("default_datetimeformat")));
			addJsonItem(stringBuilder, "testtype", EnumManagement.GetProjectTypeName(Experiment.Type));
			addJsonListItem(stringBuilder, "List", _Experiment.Wells.Where((Well s) => s.Sample != null).ToList());
			stringBuilder.Append("}");
			return stringBuilder.ToString();
		}

		public Color GetChartDataColor(EColorMode colorMode, SampleTargetItem item, Well well)
		{
			if (item.HasCustomColor(colorMode))
			{
				return item.GetCustomColor(colorMode);
			}
			switch (colorMode)
			{
			case EColorMode.Channel:
				return ConfigSettings.GetInstance().ExperimentSetting.ColorSettings.GetChannelColor(item.ChannelNo);
			case EColorMode.Type:
				return Utility.GetSampleColor(item.SampleType);
			case EColorMode.Row:
				return Utility.GetRowColor(well.RowIndex + 1);
			case EColorMode.Column:
				return Utility.GetColumnColor(well.ColumnIndex + 1);
			case EColorMode.Result:
				if (item.Result is HRMTargetResult)
				{
					return Utility.GetDrawingGenoTypeColor(((HRMTargetResult)item.Result).GenoType);
				}
				if (well.Result is ADWellResult)
				{
					return Utility.GetDrawingADGenoTypeColor(((ADWellResult)well.Result).TypeNo);
				}
				break;
			case EColorMode.Target:
				return well.Project.Target.Items.Where((TargetItem s) => s.Name == item.TargetName).FirstOrDefault().Color;
			}
			return Colors.Black;
		}

		private void addJsonListItem(StringBuilder param, string key, List<Well> wells)
		{
			param.Append("\"" + key + "\":");
			param.Append("[");
			for (int i = 0; i < wells.Count; i++)
			{
				Well well = wells[i];
				foreach (SampleTargetItem item in well.Sample.Items)
				{
					param.Append("{");
					addJsonItem(param, "fyk", well.CellName ?? "");
					addJsonItem(param, "xm", well.Project.BasicInfo.Name);
					addJsonItem(param, "ybmc", well.Sample.SampleName);
					addJsonItem(param, "gh", string.Concat(item.TubeNo));
					addJsonItem(param, "gm", item.TubeName);
					addJsonItem(param, "td", string.Concat(item.ChannelNo));
					addJsonItem(param, "rl", item.Dye);
					addJsonItem(param, "mb", item.TargetName);
					string value = GetChartDataColor(Experiment.ColorMode, item, well).ToString();
					addJsonItem(param, "ys", value);
					addJsonItem(param, "lx", EnumManagement.GetSampleTypeName(item.SampleType));
					string value2 = ((!double.IsPositiveInfinity(item.Result.CtValue)) ? item.Result.CtValue.ToString("0.00") : Utility.GetMessage("NoCt"));
					addJsonItem(param, "ct", value2);
					value2 = ResultFormat.Format(item.Result.RnValue, "0.000");
					addJsonItem(param, "rn", value2);
					StringBuilder stringBuilder = new StringBuilder();
					foreach (Conclusion conclusion in item.Result.ConclusionList)
					{
						stringBuilder.Append(conclusion.Content + " ");
					}
					if (stringBuilder.Length > 0)
					{
						stringBuilder.Remove(stringBuilder.ToString().Length - 1, 1);
					}
					addJsonItem(param, "mbjl", stringBuilder.ToString());
					stringBuilder.Clear();
					foreach (Conclusion conclusion2 in well.Result.ConclusionList)
					{
						stringBuilder.Append(conclusion2.Content + " ");
					}
					if (stringBuilder.Length > 0)
					{
						stringBuilder.Remove(stringBuilder.ToString().Length - 1, 1);
					}
					addJsonItem(param, "gjl", stringBuilder.ToString());
					stringBuilder.Clear();
					foreach (Conclusion conclusion3 in well.Sample.Result.ConclusionList)
					{
						stringBuilder.Append(conclusion3.Content + " ");
					}
					if (stringBuilder.Length > 0)
					{
						stringBuilder.Remove(stringBuilder.ToString().Length - 1, 1);
					}
					addJsonItem(param, "ybjl", stringBuilder.ToString());
					addJsonItem(param, "bs", well.Sample.PatientInfo.ID);
					addJsonArrayItem(param, "kzqx", item.Result.AMPCurve.CurvePoint, "0.00000");
					addJsonArrayItem(param, "ysqx", item.Result.RawCurve.CurvePoint, "0.00");
					if (param.ToString().LastIndexOf(",") == param.Length - 1)
					{
						param.Remove(param.Length - 1, 1);
					}
					param.Append("},");
				}
			}
			if (param.ToString().LastIndexOf(",") == param.Length - 1)
			{
				param.Remove(param.Length - 1, 1);
			}
			param.Append("]");
		}

		private void addJsonArrayItem(StringBuilder param, string key, List<Dot> Curve, string formart)
		{
			param.Append("\"" + key + "\":");
			for (int i = 0; i < Curve.Count; i++)
			{
				if (i == 0)
				{
					param.Append("[");
				}
				param.Append("\"" + Curve[i].Y.ToString(formart) + "\"");
				if (i == Curve.Count - 1)
				{
					param.Append("],");
				}
				else
				{
					param.Append(",");
				}
			}
		}

		private void addJsonItem(StringBuilder param, string key, string value, bool isLast = false)
		{
			param.Append("\"" + key + "\":\"" + value + "\"" + ((!isLast) ? "," : ""));
		}

		private void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
		{
			if (ConfigSettings.GetInstance().ExperimentSetting.CustomExport)
			{
				if (File.Exists(ExperimentSetting.InternalCustomExportName))
				{
					string text = _UCExperimentAnalysis.ExportDefaultExperimentData();
					string text2 = ((_Experiment.CurrentSubset.GetQuantitativeProjectList().Count == 0) ? "0" : "1");
					Process.Start(ExperimentSetting.InternalCustomExportName, "\"" + text + "\" " + text2 + " " + 1);
				}
			}
			else
			{
				_UCExperimentAnalysis.AutoExportExperimentData();
			}
		}

		private void worker_DoWork(object sender, DoWorkEventArgs e)
		{
			while (_UCExperimentAnalysis == null || (_UCExperimentAnalysis != null && !_UCExperimentAnalysis.isLoad))
			{
				Thread.Sleep(100);
			}
		}

		private void Root_SourceUpdated(object sender, DataTransferEventArgs e)
		{
			_IsModified = true;
		}

		private void TabControlExperiment_Initialized(object sender, EventArgs e)
		{
			if (Experiment.Status == EExperimentStatus.AbnormalInterrupt)
			{
				Experiment.Status = EExperimentStatus.NotRunning;
				TabControlExperiment.SelectedItem = TabItemExperimentRun;
				if (Experiment.Device.RunState != 0)
				{
					Experiment.Continue();
				}
			}
			else if (Experiment.Status == EExperimentStatus.Completed)
			{
				TabControlExperiment.SelectedItem = TabItemExperimentAnalysis;
			}
		}

		private void TabControlExperiment_SelectionChanged(object sender, SelectionChangedEventArgs e)
		{
			if (e.OriginalSource == TabControlExperiment)
			{
				menuWellEdit.Visibility = ((TabControlExperiment.SelectedItem != TabItemWellEdit) ? Visibility.Collapsed : Visibility.Visible);
				menuInfoEdit.Visibility = ((TabControlExperiment.SelectedItem != TabItemSampleInfo) ? Visibility.Collapsed : Visibility.Visible);
				menuChannelSelect.Visibility = ((TabControlExperiment.SelectedItem != TabItemExperimentRun && TabControlExperiment.SelectedItem != TabItemExperimentAnalysis) ? Visibility.Collapsed : Visibility.Visible);
				menuStandartCurve.Visibility = ((TabControlExperiment.SelectedItem != TabItemExperimentAnalysis || (_Experiment.Type != 0 && _Experiment.Type != EProjectType.TQ)) ? Visibility.Collapsed : Visibility.Visible);
				menuRun.Visibility = ((TabControlExperiment.SelectedItem != TabItemExperimentRun) ? Visibility.Collapsed : Visibility.Visible);
				menuAnalysis.Visibility = ((TabControlExperiment.SelectedItem != TabItemExperimentAnalysis) ? Visibility.Collapsed : Visibility.Visible);
				if (TabControlExperiment.SelectedItem == TabItemBasicSetting && !_IsGridBasicSettingInit.HasValue)
				{
					_IsGridBasicSettingInit = false;
				}
				else if (TabControlExperiment.SelectedItem == TabItemWellEdit && !_IsGridWellEditInit.HasValue)
				{
					_IsGridWellEditInit = false;
				}
				else if (TabControlExperiment.SelectedItem == TabItemSampleInfo && !_IsGridSampleInfoInit.HasValue)
				{
					_IsGridSampleInfoInit = false;
				}
				else if (TabControlExperiment.SelectedItem == TabItemExperimentRun && !_IsGridExperimentRunInit.HasValue)
				{
					_IsGridExperimentRunInit = false;
				}
				else if (TabControlExperiment.SelectedItem == TabItemExperimentRunComplete && !_IsGridExperimentRunCompleteInit.HasValue)
				{
					_IsGridExperimentRunCompleteInit = false;
				}
				else if (TabControlExperiment.SelectedItem == TabItemExperimentAnalysis && !_IsGridExperimentAnalysisInit.HasValue)
				{
					_IsGridExperimentAnalysisInit = false;
					TabItemExperimentAnalysis.Visibility = Visibility.Visible;
				}
			}
		}

		private void gridBasicSetting_Loaded(object sender, RoutedEventArgs e)
		{
			if (_IsGridBasicSettingInit == false)
			{
				_IsGridBasicSettingInit = true;
				UCBasicSetting uCBasicSetting = new UCBasicSetting(Experiment);
				uCBasicSetting.SetBinding(UCBasicSetting.IsDecryptProperty, new Binding("IsDecrypt")
				{
					Source = this
				});
				gridBasicSetting.Children.Add(uCBasicSetting);
				gridBasicSetting.Loaded -= gridBasicSetting_Loaded;
			}
		}

		private void gridWellEdit_Loaded(object sender, RoutedEventArgs e)
		{
			if (_IsGridWellEditInit == false)
			{
				_IsGridWellEditInit = true;
				_UCWellEdit = new UCWellEdit(Experiment);
				_UCWellEdit.SetBinding(UCWellEdit.IsDecryptProperty, new Binding("IsDecrypt")
				{
					Source = this
				});
				_UCWellEdit.AddHandler(UCWellEdit.OnWellPropertyChangedRoutedEvent, new RoutedEventHandler(WellEditWellPropertyChanged_RoutedEvent), true);
				_UCWellEdit.UCWellPlateWell.OnDeleteSampleAll += OnDeleteSampleAll;
				gridWellEdit.Children.Add(_UCWellEdit);
				gridWellEdit.Loaded -= gridWellEdit_Loaded;
			}
		}

		private void WellEditWellPropertyChanged_RoutedEvent(object sender, RoutedEventArgs args)
		{
			_IsModified = true;
			_RefreshProjectInfo = true;
			_refreshWell = true;
			RefreshChannelStatus();
		}

		private void RefreshChannelStatus()
		{
			List<int> list = new List<int>();
			List<Project> list2 = (from s in Experiment.Wells
				where s.Project != null
				select s.Project).Distinct().ToList();
			foreach (Project item in list2)
			{
				list.AddRange(item.Target.Items.Select((TargetItem s) => s.ChannelNo));
			}
			list = list.Distinct().ToList();
			_IsCheckChannel = false;
			foreach (int channel in channelList)
			{
				if (!list.Contains(channel))
				{
					SetChannelEnableStatus(channel, false);
				}
			}
			foreach (int item2 in list)
			{
				if (!GetChannelEnableStatus(item2))
				{
					SetChannelEnableStatus(item2, true);
				}
			}
			_IsCheckChannel = true;
			DisplayAllChannel();
			channelList = list;
		}

		private void gridSampleInfo_Loaded(object sender, RoutedEventArgs e)
		{
			if (_IsGridSampleInfoInit == false)
			{
				_IsGridSampleInfoInit = true;
				_UCSampleInfo = new UCSampleInfo(Experiment);
				_UCSampleInfo.SetBinding(UCSampleInfo.IsDecryptProperty, new Binding("IsDecrypt")
				{
					Source = this
				});
				_UCSampleInfo.UCPatientInfoForWell.OnAutoIndex += UCPatientInfoForWell_OnAutoIndex;
				gridSampleInfo.Children.Add(_UCSampleInfo);
			}
			else if (_UCSampleInfo != null)
			{
				_UCSampleInfo.RefreshSampleType();
			}
			RefreshSampleInfo();
		}

		private void UCPatientInfoForWell_OnAutoIndex(object sender, EventArgs e)
		{
			CommandBinding_AutoIndex_Executed(null, null);
		}

		private void RefreshSampleInfo()
		{
			if (_UCSampleInfo == null || TabControlExperiment.SelectedItem != TabItemSampleInfo)
			{
				return;
			}
			List<Sample> samples = (from s in Experiment.CurrentSubset.Wells
				select s.Sample into s
				where s != null && s.Items.Where((SampleTargetItem s1) => s1.SampleType == SampleType.Unknown).Count() > 0
				select s).Distinct().ToList();
			samples = GetSortedSamples(samples);
			_UCSampleInfo.UCPatientInfo.ItemsSource = samples;
		}

		private List<Sample> GetSortedSamples(List<Sample> samples)
		{
			switch (Experiment.ExperimentSetting.SampleSortMode)
			{
			case ESampleSortMode.Column:
				samples = samples.OrderBy((Sample s) => s.Wells[0].ColumnIndex).ToList();
				break;
			case ESampleSortMode.Row:
				samples = samples.OrderBy((Sample s) => s.Wells[0].RowIndex).ToList();
				break;
			case ESampleSortMode.Module:
				samples = (from s in samples
					orderby s.Wells[0].RowIndex
					orderby s.Wells[0].ModelA descending
					select s).ToList();
				break;
			}
			return samples;
		}

		private void gridExperimentRun_Loaded(object sender, RoutedEventArgs e)
		{
			if (_IsGridExperimentRunInit == false)
			{
				_IsGridExperimentRunInit = true;
				RefreshChannelStatus();
				ExperimentAnalysis(true, false);
				_UCExperimentRun = new UCExperimentRun(Experiment);
				_UCExperimentRun.SetBinding(UCExperimentRun.MaxXProperty, new Binding("MaxX")
				{
					Source = this
				});
				_UCExperimentRun.SetBinding(UCExperimentRun.CurveMaxYModeProperty, new Binding("CurveMaxYMode")
				{
					Source = _Experiment.ExperimentSetting
				});
				_UCExperimentRun.UCWellPlateRun.OnDeleteSampleAll += OnDeleteSampleAll;
				gridExperimentRun.Children.Add(_UCExperimentRun);
			}
			else if (_UCExperimentRun != null && _refreshWell)
			{
				_UCExperimentRun.RefrehSelectedWell();
				_refreshWell = false;
			}
			bool? isGridExperimentRunInit = _IsGridExperimentRunInit;
			if (isGridExperimentRunInit == true && isGridExperimentRunInit.HasValue && _UCExperimentRun != null)
			{
				_UCExperimentRun.UCWellPlateRun.RefreshSampleType();
			}
		}

		private void OnDeleteSampleAll(object sender, EventArgs e)
		{
			if (_Experiment.Status == EExperimentStatus.NotRunning || _Experiment.Status == EExperimentStatus.Interrupt)
			{
				_Experiment.Program = null;
			}
			if (_UCWellEdit != null)
			{
				_UCWellEdit.OnDeleteSampleAll();
			}
		}

		private void gridExperimentRunComplete_Loaded(object sender, RoutedEventArgs e)
		{
			if (_IsGridExperimentRunCompleteInit == false)
			{
				_IsGridExperimentRunCompleteInit = true;
				_UCExperimentRunComplete = new UCExperimentRunComplete(Experiment);
				gridExperimentRunComplete.Children.Add(_UCExperimentRunComplete);
			}
			if (_UCExperimentRunComplete != null && _RefreshProjectInfo)
			{
				_UCExperimentRunComplete.RefreshProjectInfo();
				_RefreshProjectInfo = false;
			}
		}

		private void CallAnalysis(bool isModify = false)
		{
			ExperimentAnalysis(false);
			if (isModify)
			{
				_IsModified = true;
			}
		}

		private void gridExperimentAnalysis_Loaded(object sender, RoutedEventArgs e)
		{
			if (_IsGridExperimentAnalysisInit == false)
			{
				_IsGridExperimentAnalysisInit = true;
				RefreshChannelStatus();
				comboSubset.SelectedValue = Experiment.Subsets[0];
				ExperimentAnalysis(false, false);
				switch (Experiment.Type)
				{
				case EProjectType.IA:
					if (Experiment.Program.Programs.Where((BaseSegment s) => s is MeltingSegment).Count() > 0)
					{
						_UCExperimentAnalysis = new MeltAnalysis(Experiment);
					}
					else
					{
						_UCExperimentAnalysis = new AQAnalysis(Experiment);
					}
					break;
				case EProjectType.Melt:
					_UCExperimentAnalysis = new MeltAnalysis(Experiment);
					break;
				case EProjectType.HRM:
					_UCExperimentAnalysis = new HRMAnalysis(Experiment);
					break;
				case EProjectType.AD:
					_UCExperimentAnalysis = new ADAnalysis(Experiment);
					break;
				default:
					_UCExperimentAnalysis = new AQAnalysis(Experiment);
					break;
				}
				_UCExperimentAnalysis.Analysis = CallAnalysis;
				_UCExperimentAnalysis.SetBinding(BaseAnalysis.MaxXProperty, new Binding("MaxX")
				{
					Source = this
				});
				_UCExperimentAnalysis.SetBinding(BaseAnalysis.BasicParamterVisibleProperty, new Binding("ParamterVisible")
				{
					Source = _Experiment.ExperimentSetting
				});
				_UCExperimentAnalysis.SetBinding(BaseAnalysis.WellPlateVisibleProperty, new Binding("WellPlateVisible")
				{
					Source = _Experiment.ExperimentSetting
				});
				_UCExperimentAnalysis.SetBinding(BaseAnalysis.CurveMaxYModeProperty, new Binding("CurveMaxYMode")
				{
					Source = _Experiment.ExperimentSetting
				});
				_UCExperimentAnalysis.SetBinding(BaseAnalysis.StandardCurverDisplayAllProperty, new Binding("StandardCurverDisplayAll")
				{
					Source = _Experiment.ExperimentSetting
				});
				_UCExperimentAnalysis.SetBinding(BaseAnalysis.IsDecryptProperty, new Binding("IsDecrypt")
				{
					Source = this
				});
				_UCExperimentAnalysis.ucWellPlate.OnDeleteSampleAll += OnDeleteSampleAll;
				DisplayAllChannel();
				gridExperimentAnalysis.Children.Add(_UCExperimentAnalysis);
			}
			else if (_UCExperimentAnalysis != null && _refreshWell)
			{
				_refreshWell = false;
				_UCExperimentAnalysis.RefrehSelectedWell();
			}
		}

		private void Command_CurveParameter_Executed(object sender, ExecutedRoutedEventArgs e)
		{
			if (TabControlExperiment.SelectedItem == TabItemExperimentAnalysis)
			{
				List<int> list = new List<int>();
				if (IsSelectedChannel1)
				{
					list.Add(1);
				}
				if (IsSelectedChannel2)
				{
					list.Add(2);
				}
				if (IsSelectedChannel3)
				{
					list.Add(3);
				}
				if (IsSelectedChannel4)
				{
					list.Add(4);
				}
				if (IsSelectedChannel5)
				{
					list.Add(5);
				}
				if (IsSelectedChannel6)
				{
					list.Add(6);
				}
				CurveParameterWindow curveParameterWindow = new CurveParameterWindow(_Experiment, _UCExperimentAnalysis.GetSelectedWells(), list);
				curveParameterWindow.Owner = Utility.GetMainWindow();
				if (curveParameterWindow.ShowDialog() == true)
				{
					_UCExperimentAnalysis.RefreshAllData();
					_IsModified = true;
				}
			}
		}
	}
}
